Skip to content

Instantly share code, notes, and snippets.

@sinelaw
Created February 25, 2015 00:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sinelaw/15dd1c4b9d294d621936 to your computer and use it in GitHub Desktop.
Save sinelaw/15dd1c4b9d294d621936 to your computer and use it in GitHub Desktop.
Associated types without type families - why can't this work?
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
class Indexable a where
instance Indexable (String, Int, Char) where
instance Indexable ([(String, a)], String, a) where
test1 :: Indexable (a,b,c) => a -> b -> c
test1 x y = undefined
t1 = test1 "hi" (3 :: Int)
main = return ()
-- Doesn't compile, with:
-------------------------------------------------------------------------
-- indexable.hs:13:6: --
-- No instance for (Indexable ([Char], Int, c0)) --
-- arising from a use of ‘test1’ --
-- The type variable ‘c0’ is ambiguous --
-- Relevant bindings include t1 :: c0 (bound at indexable.hs:13:1) --
-- Note: there is a potential instance available: --
-- instance Indexable (String, Int, Char) --
-- -- Defined at indexable.hs:7:10 --
-- In the expression: test1 "hi" (3 :: Int) --
-- In an equation for ‘t1’: t1 = test1 "hi" (3 :: Int) --
-------------------------------------------------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment