Sample
Last active
November 5, 2017 07:59
-
-
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
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
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