typeclass - What is the effect of type synonyms on instances of type classes? What does the TypeSynonymInstances pragma in GHC do? -


I'm reading Real World Haskell PG151, and I've seen the following passage as one For more than hours:

Remember that string is a substitute for [variable], which in turn has [a] type where the character is modeled for the parameter. According to the rules of Haskell 98, when we write an example, then we are not allowed to supply one type of substance instead of any type of parameter. In other words, writing an example for [a] would be legal for us, but not for [four]. 16 Comments 5335

It's not just drowning in. I see that too many other people are actually suffering with it I still do not understand it by comments ...

First of all, everything about it confuses me, so please if you think that you can explain anything about this path, Or TypeSynonymInstances please

Here's my problem:

  • Int a data constructor
  • string one data constructor and type synonym

Can not answer questions:

  1. Why does one type of option prevent a member from a type of class (I'm looking for some reason maybe a compilation or simulation
  2. Why were not language designers, it does not want syntax (I'm asking for logic that the broad theory or u Nickode math mark).
  3. I see this line "type [A] where variable is replaced for type parameter" , and I want to know that I Why can not I change it for "Type where format is replaced for Int." .

Thanks!

I think part of the issue is that two, roughly unrelated, ban game

  • Some types of synonyms mean that the example can be just the thing declared with data or new type , not < Code> type . It is not a forbidden string , but [char] .
  • There is no flexible example that the example can only refer to one type which is not a variable, and only that type can be used as a type of constructor Int and f int , but probably a not.

Here's information about the GHCI int , four , and string :

  data char = GHC.Types.C # GHC.Prim Four # Data Int = GHC.Type.I # GHC.Prim.Int # Type String = [Four]  

Int and four types are both simple types without variable parameters; No type of manufacturer is included, so you can make a lot more freelance examples with them.

However, the string on computation of both fails. This is a type of synonym, which is not allowed, and also a type non-variable is the constructor applied, ie the list type constructor for the variable

For comparison, note that [a] , probably a , and either are valid in all instances , But [int] , may [a] , and either string one is prohibited; Hopefully you can see why now.

For your straightforward questions, I do not know how the original intention was to design the language, and I am not able to give an official statement about it. "Best Practices", but for my own personal coding, I really do not hesitate to use these progressions:

  {- # LANGUAGE generalized newpropadding # -} {- # LANGUAGE EmptyDataDecls # -} {- # LANGUAGE TypeName Positions # -} {- # LANGUAGE Flexible Difference # -} {- # LANGUAGE FlexibleContexts # -}  

You can always see that Flexible For example, receive fair use, and "respectable" packages (for example, for parsec sour Some hit) in damages.


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -