Skip to content

Instantly share code, notes, and snippets.

@dwhitney
Last active September 21, 2017 21:47
Show Gist options
  • Save dwhitney/c6197305553dc2b94e87e90482d08e96 to your computer and use it in GitHub Desktop.
Save dwhitney/c6197305553dc2b94e87e90482d08e96 to your computer and use it in GitHub Desktop.
Variant exaple
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