Last active
May 15, 2018 06:27
-
-
Save lgastako/959be0cbf06ed12377c5f0872d6228a3 to your computer and use it in GitHub Desktop.
This file contains 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
type Enum a | |
= Enum | |
{ predFn : a -> Maybe a | |
, succFn : a -> Maybe a | |
} | |
pred : Enum a -> a -> Maybe a | |
pred (Enum { predFn }) = | |
predFn | |
succ : Enum a -> a -> Maybe a | |
succ (Enum { succFn }) = | |
succFn | |
intEnum : Enum Int | |
intEnum = | |
Enum | |
{ predFn = \x -> Just (x - 1) | |
, succFn = \x -> Just (x + 1) | |
} | |
boolEnum : Enum Bool | |
boolEnum = | |
Enum | |
{ predFn = | |
\b -> | |
if b then | |
Just False | |
else | |
Nothing | |
, succFn = | |
\b -> | |
if not b then | |
Just True | |
else | |
Nothing | |
} |
Author
lgastako
commented
May 15, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment