Created
February 25, 2015 00:31
-
-
Save sinelaw/15dd1c4b9d294d621936 to your computer and use it in GitHub Desktop.
Associated types without type families - why can't this work?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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