Last active
September 21, 2017 21:47
-
-
Save dwhitney/c6197305553dc2b94e87e90482d08e96 to your computer and use it in GitHub Desktop.
Variant exaple
This file contains hidden or 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 (Eff) | |
import Control.Monad.Eff.Console (CONSOLE, log) | |
import Data.Variant (SProxy(SProxy), Variant, inj, match) | |
oneTwoThree :: Variant (one :: String, two :: Boolean, three :: Number) -> String | |
oneTwoThree = match { | |
one : \a -> a | |
, two : \b -> show b | |
, three : \t -> show t | |
} | |
main :: forall e. Eff (console :: CONSOLE | e) Unit | |
main = do | |
log $ oneTwoThree (inj (SProxy :: SProxy "one") "Hello, World!") | |
log $ oneTwoThree (inj (SProxy :: SProxy "two") true ) | |
log $ oneTwoThree (inj (SProxy :: SProxy "three") 1.1) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment