Skip to content

Instantly share code, notes, and snippets.

@nwf
Created September 20, 2012 17:46
Show Gist options
  • Save nwf/3757318 to your computer and use it in GitHub Desktop.
Save nwf/3757318 to your computer and use it in GitHub Desktop.
Haskell closed classes using DataKinds
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE MultiParamTypeClasses #-}
-- Needed only for example below
-- {-# LANGUAGE UndecidableInstances #-}
data T1 = T1A | T1B
class Test (a :: T1) b | a -> b, b -> a where tcc :: b -> String
instance Test T1A Int where tcc = show
instance Test T1B [Char] where tcc = id
-- New instances fail with fundep conflicts. Try, for example,
-- instance Test T1A Float where tcc = show
-- instance Test a Float where tcc = show
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment