This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object FizzBuzz { | |
def main(args: Array[String]) { | |
val fizzbuzz = (1 to 100).map { i => | |
(i % 3, i % 5) match { | |
case (0, 0) => "fizzbuzz" | |
case (0, _) => "fizz" | |
case (_, 0) => "buzz" | |
case _ => i.toString | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE FlexibleInstances #-} | |
main = do | |
print $ mySum ([1, 2, 3] :: [Int]) | |
print $ mySum (["hoge", "piyo", "huga"] :: [String]) | |
class AddMonoid a where | |
unit :: a | |
add :: a -> a -> a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package info.biacco42.test.typeclass | |
/** | |
* Created by sanok on 2017/05/25. | |
*/ | |
trait Addable[T] { | |
val unit: T | |
def add(x: T, y: T): T |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(1 ..< 100).forEach { | |
switch ($0 % 3, $0 % 5) { | |
case (0, 0): | |
print("FizzBuzz") | |
case (0, _): | |
print("Fizz") | |
case (_, 0): | |
print("Buzz") | |
default: | |
print($0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Main extends App{ | |
implicit val createValueInt: Int = 3 | |
implicit val createValueStrign: String = "po" | |
def createValue[T](implicit value: T) = value | |
val valueInt: Int = createValue | |
println(valueInt) | |
val valueString: String = createValue |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Main extends App{ | |
trait Creatable[T] { | |
def create(): T | |
} | |
class Cat(val name: String) | |
// 自作の型への適用 | |
implicit object Cat extends Creatable[Cat] { | |
def create() = new Cat("taro") |
NewerOlder