Skip to content

Instantly share code, notes, and snippets.

@tonymorris
Created February 9, 2015 01:44
Show Gist options
  • Save tonymorris/562eb070ca1feecfd755 to your computer and use it in GitHub Desktop.
Save tonymorris/562eb070ca1feecfd755 to your computer and use it in GitHub Desktop.
Higher-kinds and type-classes are distinct concepts.
{-# LANGUAGE RankNTypes #-}
module Functor where
import Prelude(
foldr
, (.)
, Maybe(Nothing, Just)
, maybe
)
data Functor f =
Functor {
fmap :: forall a b. (a -> b) -> f a -> f b
}
instanceList ::
Functor []
instanceList =
Functor (\f -> foldr ((:) . f) [])
instanceMaybe ::
Functor Maybe
instanceMaybe =
Functor (\f -> maybe Nothing (Just . f))
instanceReader ::
Functor ((->) t)
instanceReader =
Functor (.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment