Skip to content

Instantly share code, notes, and snippets.

@kseo
Last active March 8, 2016 15:00
Show Gist options
  • Save kseo/8db075d9a13143f54dfb to your computer and use it in GitHub Desktop.
Save kseo/8db075d9a13143f54dfb to your computer and use it in GitHub Desktop.
The Constraint kind
-- https://jeltsch.wordpress.com/2013/02/14/the-constraint-kind/
{-# LANGUAGE ConstraintKinds, TypeFamilies #-}
import Prelude hiding (Monad (..))
import Data.Set
import GHC.Exts (Constraint)
setReturn :: el -> Set el
setReturn = singleton
setBind :: (Ord el, Ord el') =>
Set el -> (el -> Set el') -> Set el'
setBind set1 gen2 = unions (Prelude.map gen2 (toList set1))
class Monad mon where
type Object mon val :: Constraint
type Object mon val = ()
return :: Object mon val =>
val -> mon val
(>>=) :: (Object mon val, Object mon val') =>
mon val -> (val -> mon val') -> mon val'
instance Monad Set where
type Object Set el = Ord el
return = setReturn
(>>=) = setBind
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment