Skip to content

Instantly share code, notes, and snippets.

@hardvain
hardvain / Evaluator.idr
Last active November 5, 2017 07:59
[Gaining a Monad Intuition] Learn why the monad design pattern came into existence #monads #functional-programming #haskell
module IParsec
interface Source a where
feed : Nat -> a -> (List Char, a)
next : a -> (List Char, a)
next = feed 1
Source String where
feed x string = let (first, second) = splitAt x $ unpack string in
(first, pack second)
val l = 1 :: "hello" :: true :: HNil
// l: shapeless.::[Int,shapeless.::[String,shapeless.::[Boolean,shapeless.HNil]]] = 1 :: hello :: true :: HNil
l.head
// res7: Int = 1
l.tail
// res8: shapeless.::[String,shapeless.::[Boolean,shapeless.HNil]] = hello :: true :: HNil
l(1)
import shapeless._
val hlist1a = HList(1,2,3)
val hlist2a = HList(1,"a",3.14)
// The above code with type ascription
val hlist1b: ::[Int, ::[Int, ::[Int, HNil]]] = HList(1,2,3)
val hlist2b: ::[Int, ::[String, ::[Double, HNil]]] = HList(1,"a",3.15)
val list1 : List[Int] = List(1,2,3) // list of integers
val list2 : List[String] = List("a","b", "c") // list of strings
val list3 : List[Any] = List(1,2,"a","b") // list of any. Here Any is the least upper bound of sting & int
libraryDependencies += "com.chuusai" % "shapeless_2.11" % "2.3.2"