Skip to content

Instantly share code, notes, and snippets.

@tonymorris
Created July 8, 2019 12:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tonymorris/6c6ca0f7deb05554287b1adf4aa5604d to your computer and use it in GitHub Desktop.
Save tonymorris/6c6ca0f7deb05554287b1adf4aa5604d to your computer and use it in GitHub Desktop.
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