Last active
February 17, 2018 04:20
-
-
Save emilypi/442b1a71bcdbf5a07849817f5a5d5bbe to your computer and use it in GitHub Desktop.
Creating a simple function in Idris for you to play with
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 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