Last active
April 14, 2018 08:28
-
-
Save LeifW/eabdd49a6b2b72c42aa216cb0166e67c to your computer and use it in GitHub Desktop.
Natural transformation typeclass
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
{-# 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 |
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
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