Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@nonowarn
Created March 2, 2010 11:16
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 nonowarn/319439 to your computer and use it in GitHub Desktop.
Save nonowarn/319439 to your computer and use it in GitHub Desktop.
Equality on Types
-- based on http://okmij.org/ftp/Haskell/de-typechecker.lhs
{-# LANGUAGE IncoherentInstances,UndecidableInstances #-}
data HTrue
data HFalse
instance Show HTrue where show _ = "HTrue"
instance Show HFalse where show _ = "HFalse"
class TypeEq x y b | x y -> b where
type'eq :: x -> y -> b
type'eq _ _ = undefined
instance (b ~ HTrue) => TypeEq x x b
instance (b ~ HFalse) => TypeEq x y b
-- *Main> type'eq True "True"
-- HFalse
-- *Main> type'eq True False
-- HTrue
-- *Main> type'eq id id
-- HFalse
-- *Main> type'eq putStr putStrLn
-- HTrue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment