Created
July 8, 2019 12:10
-
-
Save tonymorris/6c6ca0f7deb05554287b1adf4aa5604d 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
data Hi = | |
Hi1 Int | |
| Hi2 String | |
| Hi3 [Int] | |
deriving (Eq, Show) | |
-- generate this: | |
class AsHi a where | |
_Hi :: | |
a | |
-> Hi | |
_Hi1 :: | |
a | |
-> Maybe Int | |
_Hi1 a = | |
case _Hi a of | |
Hi1 n -> | |
Just n | |
_ -> | |
Nothing | |
_Hi2 :: | |
a | |
-> Maybe String | |
_Hi2 a = | |
case _Hi a of | |
Hi2 s -> | |
Just s | |
_ -> | |
Nothing | |
_Hi3 :: | |
a | |
-> Maybe [Int] | |
_Hi3 a = | |
case _Hi a of | |
Hi3 n -> | |
Just n | |
_ -> | |
Nothing | |
instance AsHi Hi where | |
_Hi = | |
id |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment