Skip to content

Instantly share code, notes, and snippets.

@emilypi
Last active February 17, 2018 04:20
Show Gist options
  • Save emilypi/442b1a71bcdbf5a07849817f5a5d5bbe to your computer and use it in GitHub Desktop.
Save emilypi/442b1a71bcdbf5a07849817f5a5d5bbe to your computer and use it in GitHub Desktop.
Creating a simple function in Idris for you to play with
module Foo
public export
data Foo = Try Int | Again Int
implementation Show Foo where
show (Try n) = "(Try " ++ (show n) ++ ")"
show (Again n) = "(Again " ++ (show n) ++ ")"
export
bar : Foo -> String
bar = show
-- but suppose we have a double in the mix
-- Now, this is isomorphic to Either Int Double
public export
data NewFoo = NTry Int | NAgain Double
export
qux : NewFoo -> Either Int Double
qux (NTry n) = Left n
qux (NAgain d) = Right d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment