This file contains hidden or 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
trait Hoge { | |
protected val hoge: String | |
lazy val l = hoge.length | |
} | |
trait Piyo { | |
this: Hoge => | |
val p = l | |
} |
This file contains hidden or 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
import Data.List | |
main = do | |
l <- fmap toInt $ getLine -- 標準入力からLを読み込む | |
n <- fmap toInt $ getLine -- 標準入力からNを読み込む(使わない | |
bars <- fmap (fmap toInt . lines) $ getContents -- 残りのリストを取得 | |
print (sum $ fmap (findTripleSum l) $ tails bars) -- tails で部分リストを順番に調べる | |
-- Int化 | |
toInt :: [Char] -> Int |
This file contains hidden or 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
module ElemCount where | |
import Data.List | |
-- | for empty list | |
-- | |
-- >>> elemCountOrd [] | |
-- [] | |
-- | |
-- | count the same element |
This file contains hidden or 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
// "sealed" : Declare that no other subclass except this file. This helps compiler to verify loss of pattern. | |
sealed trait Expression { | |
def a: Int | |
def b: Int | |
} | |
case class Addition(a: Int, b: Int) extends Expression | |
case class Subtraction(a: Int, b: Int) extends Expression | |
case class Multiply(a: Int, b: Int) extends Expression | |
case class Division(a: Int, b: Int) extends Expression |
This file contains hidden or 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
class A | |
class B extends A | |
class C extends A | |
def isType[T <: A](a: A) = a.isInstanceOf[T] | |
// <console>:9: warning: abstract type T is unchecked since it is eliminated by erasure | |
// def isType[T <: A](a: A) = a.isInstanceOf[T] | |
// ^ | |
// isType: [T <: A](a: A)Boolean |
This file contains hidden or 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
import scala.reflect.ClassTag | |
object Hoge { | |
def main(args: Array[String]) = { | |
val s = new Hoge[StringSample] | |
val i = new Hoge[IntSample] | |
s.detectType(StringSample("hogehoge")) //=> detected! | |
s.detectType(IntSample(1)) | |
i.detectType(StringSample("hogehoge")) | |
i.detectType(IntSample(2)) //=> detected! |
This file contains hidden or 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
import java.io._ | |
import java.lang.Math | |
import scala.annotation.tailrec | |
/** | |
* ref: http://justindomke.wordpress.com/2008/11/29/mandelbrot-in-scala/ | |
*/ | |
object mandelbrot { | |
// tiny complex number class including syntactic sugar for basic operations |
This file contains hidden or 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
trait SampleParsers extends RegexParsers { | |
/** 文字列に".i"を付けると大文字小文字を区別せずマッチさせるようにする拡張 */ | |
implicit class IgnoreCaseString(s: String) { | |
def i: Parser[String] = ("""(?i)\Q""" + s + """\E""").r | |
} | |
def keyword: Parser[String] = "keyword:".i | |
def value: Parser[String] = "[a-zA-Z0-9]+".r | |
def parameter: Parser[(String,String)] = keyword ~ value ^^ { case k~v => (k,v) } | |
} |
This file contains hidden or 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
FROM debian:latest | |
MAINTAINER mather <[email protected]> | |
RUN apt-get update | |
RUN apt-get autoremove -y | |
RUN apt-get install -y wget openjdk-7-jre | |
RUN wget http://downloads.typesafe.com/scala/2.11.1/scala-2.11.1.deb | |
RUN dpkg -i scala-2.11.1.deb |
This file contains hidden or 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
import akka.actor.{ExtendedActorSystem, Extension, ExtensionId} | |
class SampleExtentionImpl(system: ExtendedActorSystem) extends Extension { | |
val hoge = "HOGE" | |
} | |
object SampleExtension extends ExtensionId[SampleExtensionImpl] { | |
def createExtension(system: ExtendedActorSystem) = new SampleExtensionImpl(system) | |
} |