Created
June 27, 2014 07:35
-
-
Save yuga/cddccb44542e7b148e39 to your computer and use it in GitHub Desktop.
typeclass0.hs の例でのコンパイルエラーを前に少し悩んだので。
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
class Producer p where | |
get :: Resource r => p -> r | |
class Resource a where | |
fire :: a -> Int | |
data A = A Int | |
data B = B Int | |
instance Producer A where | |
get (A x) = B x | |
instance Resource B where | |
fire (B x) = x | |
c = A 32 | |
r = get c :: B | |
a = fire r | |
{- | |
typeclass0.hs|11 col 18 error| Could not deduce (r ~ B) | |
|| Could not deduce (r ~ B) | |
|| from the context (Resource r) | |
|| bound by the type signature for get :: Resource r => A -> r | |
|| at test.hs:11:6-20 | |
-} |
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 MultiParamTypeClasses #-} | |
class Producer p r where | |
get :: Resource r => p -> r | |
class Resource a where | |
fire :: a -> Int | |
data A = A Int | |
data B = B Int | |
instance Producer A B where | |
get (A x) = B x | |
instance Resource B where | |
fire (B x) = x | |
c = A 32 | |
r = get c :: B | |
a = fire r |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment