Closed AnthonyJacob closed 6 years ago
It's expressed via a Scott encoding:
https://github.com/Gabriel439/Haskell-Morte-Library/blob/master/Prelude/Maybe/Just
https://github.com/Gabriel439/Haskell-Morte-Library/blob/master/Prelude/Maybe/Nothing
Which looks like this in Haskell:
type Maybe' a
= forall b. (a -> b) -> b -> b
just :: a -> Maybe' a
just a f _ = f a
nothing :: Maybe' a
nothing _ a = a
See also this library:
https://github.com/Gabriel439/Haskell-Annah-Library
... which automates Church encoding data types and this blog post which explains the process:
Suppose I have the following line of code in Haskell
How do I compile it to morte expression and then back to Haskell again?