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> trait Assoc[K] { type V ; val value: V } | |
defined trait Assoc | |
scala> def mkAssoc[K, V0](k: K, v: V0): Assoc[k.type] { type V = V0 } = | |
| new Assoc[k.type] { type V = V0 ; val value = v } | |
mkAssoc: [K, V0](k: K, v: V0)Assoc[k.type]{type V = V0} | |
scala> def lookup[K](k: K)(implicit assoc: Assoc[k.type]): assoc.V = assoc.value | |
lookup: [K](k: K)(implicit assoc: Assoc[k.type])assoc.V |
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
// Updated for Scala 2.10.0. | |
def kind[A: scala.reflect.runtime.universe.TypeTag](a: A): String = { | |
import scala.reflect.runtime.universe._ | |
def typeKind(sig: Type): String = sig match { | |
case PolyType(params, resultType) => | |
(params map { p => | |
typeKind(p.typeSignature) match { | |
case "*" => "*" | |
case s => "(" + s + ")" | |
} |
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
case class T() // your data type that you want to "implicitly" thread through | |
case class TReader[+A](run: T ⇒ A) { | |
def map[B](f: A ⇒ B): TReader[B] = | |
TReader((r: T) ⇒ f(run(r))) | |
def flatMap[B](f: A ⇒ TReader[B]): TReader[B] = | |
TReader((r: T) ⇒ f(run(r)).run(r)) | |
def &&&[B](x: TReader[B]): TReader[(A, B)] = |
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
$ ghci | |
GHCi, version 7.4.2: http://www.haskell.org/ghc/ :? for help | |
Loading package ghc-prim ... linking ... done. | |
Loading package integer-gmp ... linking ... done. | |
Loading package base ... linking ... done. | |
Prelude> :l hello-ski.hs | |
[1 of 1] Compiling Main ( hello-ski.hs, interpreted ) | |
Ok, modules loaded: Main. | |
*Main> main | |
Hello world! |
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
-- courtesy of hpc on #haskell | |
import Unsafe.Coerce | |
import Control.Monad.ST | |
toInteger :: Int -> Integer | |
isJust :: Maybe a -> Bool | |
null :: [a] -> Bool | |
id :: a -> a | |
toInteger = unsafeCoerce |