Skip to content

Instantly share code, notes, and snippets.

@LeifW
Last active April 14, 2018 08:28
Show Gist options
  • Save LeifW/eabdd49a6b2b72c42aa216cb0166e67c to your computer and use it in GitHub Desktop.
Save LeifW/eabdd49a6b2b72c42aa216cb0166e67c to your computer and use it in GitHub Desktop.
Natural transformation typeclass
{-# LANGUAGE MultiParamTypeClasses, TypeOperators #-}
import Data.Maybe (maybeToList)
class (~>) m n where
nt :: m x -> n x
instance (~>) Maybe [] where
nt = maybeToList
doTheThing :: m ~> n => m x -> n x
doTheThing = nt
x :: [Int]
x = doTheThing $ Just 10
infixl 3 ~>
interface (~>) (m : Type -> Type) (n : Type -> Type) where
nt : m x -> n x
(~>) Maybe List where
nt = toList
doTheThing : m ~> n => m x -> n x
doTheThing = nt
x : List Int
x = doTheThing $ Just 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment