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
let inline speak (a: ^a) = | |
let x = (^a : (member Name: string) (a)) | |
printfn "I'm %s" x | |
let y = (^a : (member talk: unit -> string) (a)) | |
printfn "I say %s" y | |
//type Duck = | |
// { Name : string } // Name is not property in F# 2.0 | |
// | |
// member x.talk() = "quackity quack" |
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 OverloadedStrings #-} | |
import Data.Conduit | |
import Data.Conduit.Network | |
import Data.Conduit.Text (encode, decode, utf8) | |
import qualified Data.Conduit.List as CL | |
import qualified Data.Conduit.Binary as CB | |
import Data.Text (toUpper) | |
import qualified Data.ByteString.Char8 as S8 |
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
(use 'clojure.core.logic) | |
(def _1 [()]) | |
(def _2 [() ()]) | |
(def _3 [() () ()]) | |
(def _4 [() () () ()]) |
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
// import scala.collection.JavaConversions._ | |
scala> val git = new Git(new FileRepositoryBuilder().findGitDir(new java.io.File("/path/to/repos")).readEnvironment().build()) | |
git: org.eclipse.jgit.api.Git = org.eclipse.jgit.api.Git@18ed36fb | |
scala> git.log.addPath("foo").call.head | |
res49: org.eclipse.jgit.revwalk.RevCommit = commit c4554d9f46de49e449242a2aa75d39874dc99498 1342332998 ----sp | |
scala> git.log.addPath("foo").call.headOption | |
res50: Option[org.eclipse.jgit.revwalk.RevCommit] = Some(commit d3107ef998b25d70f86f1a5d530c31c02507d59e 1342012813 ----sp) |
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
lazy val fab: PartialFunction[Base, Int] = { | |
case A(base) => 1 + fabc(base) // PartialFunction#apply の呼び出し。危ない! | |
case B(left, right) => 1 + fabcd(left) + fabcd(right) // 同様 | |
} | |
// 全域関数だと scala コンパイラにはわからない! | |
lazy val fabcd: PartialFunction[Base, Int] = fab orElse { | |
case C => 1 | |
case D => 2 | |
} |
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
imoprt Iteratee._ | |
lazy val takeOdds = { | |
val aux = for { | |
one <- headOption[Byte[Array]] // ダサい | |
_ <- headOption[Byte[Array]] // ダサい | |
} yield one | |
for { | |
odds <- aux |
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
scala> def add(i: Int)(words: String) = words.map({x: Char => x + i - 'a'} andThen Stream.continually(Range.inclusive('a', 'z')).flatten andThen {_.toChar}) | |
add: (i: Int)(words: String)String | |
scala> add(2)("abcdz") | |
res16: String = cdefb |
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
/** | |
* this is an experiment to create unboxed union types with a phantom type and a context bound. | |
* All the good ideas come from @milessabin post, comments and links: http://www.chuusai.com/2011/06/09/scala-union-types-curry-howard/#comment-22 | |
*/ | |
/** trait for anything that can be A or B */ | |
trait Or[A, B] { | |
// a phantom type, there will be no instance of this type that we'll use | |
type l[T] | |
// an alias for l[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
{-# OPTIONS_GHC -fwarn-incomplete-patterns #-} | |
module TuringMachine where | |
import Control.Applicative | |
import Control.Arrow hiding (left, right) | |
import Control.Lens hiding (Tape, Zipper, left, right) | |
import Data.List.Lens | |
import qualified Data.Map as M | |
import Data.Maybe | |
data Instruction s = GoLeft |
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 ExtendedDefaultRules, OverloadedStrings #-} | |
{-# OPTIONS_GHC -fno-warn-type-defaults #-} | |
module Main where | |
import Control.Monad | |
import qualified Data.List as List | |
import Data.Monoid | |
import qualified Data.Text.Lazy as LT | |
import Filesystem.Path.CurrentOS hiding (fromText, (<.>)) | |
import Shelly | |
import System.Environment |