Skip to content

Instantly share code, notes, and snippets.

@tim2CF
Created May 5, 2020 12:07
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 tim2CF/4eea37546f94189de0167a928813ff97 to your computer and use it in GitHub Desktop.
Save tim2CF/4eea37546f94189de0167a928813ff97 to your computer and use it in GitHub Desktop.
{-# LANGUAGE MultiParamTypeClasses #-}
module Injective
( Injective (..),
Foo (..),
)
where
class Injective a b where
to :: a -> b
from :: b -> Maybe a
data Foo = Foo | Bar | Buz
instance Injective Bool Foo where
to True = Foo
to False = Bar
from Foo = Just True
from Bar = Just False
from Buz = Nothing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment