Created
June 23, 2017 07:58
-
-
Save dcastro/25fe77ed183b03aba98b520aae03e759 to your computer and use it in GitHub Desktop.
Church-encoding of `Option`/Maybe` in Purescript
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 Main where | |
import Prelude | |
import Control.Monad.Eff.Console | |
import Data.Foldable (foldMap) | |
import TryPureScript | |
type Option a = forall b. (a -> b) -> b -> b | |
some :: forall a. a -> Option a | |
some a = \f -> \_ -> f a | |
none :: forall a. Option a | |
none = \_ -> \g -> g | |
main = render $ foldMap (h1 <<< text) results | |
where | |
results = [ | |
some "hello world" id "nothing to see here", | |
none id "nothing to see here" | |
] | |
-- see http://try.purescript.org/?gist=8eb5f6823fb4d3a447109718f1b4e5c3&session=4cb2af31-96b0-7c3c-ed4c-a37170a211ba |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment