Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修正第 6 章的翻译 #104

Open
huangzworks opened this issue Jan 16, 2016 · 1 comment
Open

修正第 6 章的翻译 #104

huangzworks opened this issue Jan 16, 2016 · 1 comment

Comments

@huangzworks
Copy link
Owner

No description provided.

@scarletsky
Copy link
Contributor

考虑下加入 FlexibleInstancesTypeSynonymInstances 的区别?

Making an instance with a type synonym 一节第二段 ,里面有位 piu 的用户的留言写得挺好的,我贴一下:

piu 2010-11-01

instance JSON [Char] needs the FlexibleInstances pragma,
instance JSON String needs the TypeSynonymInstances pragma.

these are different problems, I think, even if they might often be related.

simple example:
----------------------
given the following type and typeclass:

data (Num a) => Vector a = Vector a a
deriving (Show)

class MyClass a where
myFun :: a -> a

it seems perfectly ok to define (without the need of any pragma)

instance MyClass (Vector a) where
myFun = id

myFun (Vector 1 2) :: Vector Int gives Vector 1 2, myFun (Vector 1 2) :: Vector Double gives Vector 1.0 2.0 instead.

but if you try to define

instance MyClass (Vector Int) where etc…
instance MyClass (Vector Double) where etc…

- perhaps because you want to handle those types of vectors differently - you will need the FlexibleInstances pragma. and if you try to work around this problem by introducing two new type synonyms

type VectorInt = Vector Int
type VectorDouble = Vector Double

and using them in the instance declaration

instance MyClass VectorInt where etc…

you will need the TypeSynonymInstances pragma instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants