Skip to content

Instantly share code, notes, and snippets.

@maoe
Created March 7, 2011 17:51
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 maoe/858876 to your computer and use it in GitHub Desktop.
Save maoe/858876 to your computer and use it in GitHub Desktop.
MPTCs + fundepsとtype familiesは型の上の関数
{-# LANGUAGE UndecidableInstances, FlexibleInstances #-}
{-# LANGUAGE TypeFamilies, FunctionalDependencies, MultiParamTypeClasses #-}
data Z
data S n
class Plus m n r | m n -> r
instance Plus Z n n
instance Plus m n r => Plus (S m) n (S r)
two = undefined :: Plus (S Z) (S Z) r => r
type family Plus' m n :: *
type instance Plus' Z n = n
type instance Plus' (S m) n = S (Plus' m n)
two' = undefined :: Plus' (S Z) (S Z)
{-
Prelude> :t two
two :: S (S Z)
Prelude> :t two'
two' :: S (S Z)
-}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment