Skip to content

Instantly share code, notes, and snippets.

@hardvain
Last active November 5, 2017 07:59
Show Gist options
  • Save hardvain/cb7c9ac81973e1b6c1eaf4ef360efc37 to your computer and use it in GitHub Desktop.
Save hardvain/cb7c9ac81973e1b6c1eaf4ef360efc37 to your computer and use it in GitHub Desktop.
[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)
Parser : Source s => s -> Type -> Type
Parser s type = s -> List (type, s)
item : Source s => Parser s Char
item = \source => case next source of
([], _) => []
([x], rest) => [(x, rest)]
result : Source s => a -> Parser s a
result a = \source => [(a, source)]
zero : Source s => Parser s a
zero = \source => []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment