Skip to content

Instantly share code, notes, and snippets.

@dcastro
Created June 23, 2017 07:58
Show Gist options
  • Save dcastro/25fe77ed183b03aba98b520aae03e759 to your computer and use it in GitHub Desktop.
Save dcastro/25fe77ed183b03aba98b520aae03e759 to your computer and use it in GitHub Desktop.
Church-encoding of `Option`/Maybe` in Purescript
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