Why can not I write:
data color = R | G. B. Show sarcastic show color: Show color Show color = color show Main = Do put STRLN (Show Corer. Show R) putStrLn (Shockler. Show G)
Why Examples of Classes First Class Are not the citizens of Haskel?
It is difficult to discuss why is a definite feature of the language, Because only language designers can really answer it. What has happened though, is that they have decided that there can be one example for each type of each class. It is likely to be inspired by the fact that examples are used inherently in a class.
square fu is one where foo :: a -> The string
and this module
import A - defines an example Foo Int bar :: int - & gt; The string bar is n = "number is" ++ foo n
bar
function interconnected reference module A < Example of / code> Now suppose we add another import import A - defines an example Fu Inter imports B - defines another example Foo Int bar: : Int - & gt; String bar n = "number is" ++ foo n
It is now unclear, Hoskel may have provided a syntax for clarifying it, but instead opted to reject it . One advantage is that whichever code reads, it can find easy-to-use examples, because only one can be.
Many examples may be partially simulated, however. A GHC extension allows each to define an inherent parameter, to specify a different "example" for those parameters in the function call:
{- # LANGUAGE ImplicitParams # } Data color = R | G. B. Shaw Kolor :: (? Shosi :: Rang -> String) = & gt; Color - & gt; String Show Collar C = "Color:" ++? Show cc :: Io (main) = Come on? Show c = \ c - & gt; RC C-C - & gt; "Red"; _ - & gt; Is "No No" in PutStrLn (ShowColor B)? ShowC = \ c - & gt; G's case C - & gt; "Green" ; _ - & gt; PutStrLn (ShowColor B) does not have "green"
The above is the output:
is color: not red color: not green
Agda does not have a type of class in the programming language, but it has played a similar role there, for example (as Haskel) has passed, but if desired you manually override the underlying logic And to specify a different example, using special syntax Are spun.
No comments:
Post a Comment