Guest User

Untitled

a guest
Apr 1st, 2020
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. instance Functor Parsa where
  2.   fmap u (Parsa runner) =
  3.     Parsa $ \input -> do
  4.       (input2, x) <- runner input
  5.       Solo (input2, u x)
  6.  
  7. instance Applicative Parsa where
  8.   pure a = Parsa $ \s -> Solo (s, a)
  9.   (<*>) (Parsa f) (Parsa x) = Parsa qux
  10.     where
  11.       qux = \s -> do
  12.         (s2, y) <- x s
  13.         (s3, z) <- f s2
  14.         Solo (s3, z y)
  15.  
  16. instance Monad Parsa where
  17.   (>>=) (Parsa x) f = Parsa quux
  18.     where
  19.       quux = \s -> do
  20.         (s2, y) <- x s
  21.         (s3, z) <- runParsa (f y) s2
  22.         Solo (s3, z)
  23.   return x = Parsa (\s -> Solo (s, x))
Advertisement
Add Comment
Please, Sign In to add comment