Skip to content

Instantly share code, notes, and snippets.

@LeifW
Last active May 23, 2020 07:57
Show Gist options
  • Save LeifW/8f99aaca6d63b28f195e to your computer and use it in GitHub Desktop.
Save LeifW/8f99aaca6d63b28f195e to your computer and use it in GitHub Desktop.
A Num instance for Type
import Data.Vect
%default total
Num Type where
(+) = Either
(*) = Pair
fromInteger 0 = Void
fromInteger 1 = Unit
fromInteger 2 = Bool
fromInteger n = Vect (fromInteger n) Unit
-- Now you can use arithmetic expressions as type signatures:
a : 1
a = ()
b : 1 * 2
b = ((), True)
c : 0 + 2
c = Right False
me : String * Int
me = ("Leif", 36)
three : 3
three = [(), (), ()]
@LeifW
Copy link
Author

LeifW commented May 23, 2020

%default total

peanoType : Nat -> Type
peanoType Z = Void
peanoType (S Z) = Unit
peanoType (S (S Z)) = Bool
peanoType (S (S (S n))) = Maybe $ peanoType (S (S n))

Num Type where
  (+) = Either
  (*) = Pair
  fromInteger n = peanoType $ fromIntegerNat n


-- Now you can use arithmetic expressions as type signatures:

a : 1
a = ()

b : 1 * 2
b = ((), True)

c : 0 + 2
c = Right False

me : String * Int
me = ("Leif", 36)

wierd : 3
wierd = Just False

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment