I am trying to understand how to interpret type variables in Haskell class declarations from a paper. With respect to the code below I have the following questions: 1. What is the difference between "a b" in the header of the Container class and "a b" in the signature of the class methods? Does the whitespace in header mean 2 distinct types and in the methods mean function application? 2. In the Boathouse class what is the difference between the first ocurance of "b p" and the second bracketed "(b p)"? 3. When I try to make instance of these classes I seem to need FlexibleInstances. Why is this? {-# LANGUAGE MultiParamTypeClasses #-} -- Containers a b stands for all container types a holding things of type b. -- from :info command a has kind *->*, b has kind * class Containers a b where insert :: b -> a b -> a b remove :: b -> a b -> a b whatsIn :: a b -> [b] class Surfaces a b where put :: b -> a b -> a b takeOff :: b -> a b -> a b whatsOn :: a b -> [b] -- from :info command "p" has kind *, "h" and "b" have kind *->* class People p class Containers h p => Houses h p where class (People p, Surfaces h p) => Boats h p where class (Boats b p,Houses h (b p)) => BoatHouses h b p where class (People p, Houses h (b p),Boats b p) => HouseBoats h b p This email originated from DIT. If you received this email in error, please delete it from your system. Please note that if you are not the named addressee, disclosing, copying, distributing or taking any action based on the contents of this email or attachments is prohibited. www.dit.ie Is ó ITBÁC a tháinig an ríomhphost seo. Má fuair tú an ríomhphost seo trí earráid, scrios de do chóras é le do thoil. Tabhair ar aird, mura tú an seolaí ainmnithe, go bhfuil dianchosc ar aon nochtadh, aon chóipeáil, aon dáileadh nó ar aon ghníomh a dhéanfar bunaithe ar an ábhar atá sa ríomhphost nó sna hiatáin seo. www.dit.ie Tá ITBÁC ag aistriú go Gráinseach Ghormáin – DIT is on the move to Grangegorman _______________________________________________ Beginners mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners |
1, a and b are distinct types. However b is of kind * while a is of kind * -> *, which means it takes a type and returns a type. That means that b can be a type like Int, (), or Char, while a has to be a type like Maybe, [], or (Either ()). That way they fit together into a type like (Maybe Char) or [Int]. 2. In the constraint Boats b p, there it says b and p are two types that form an instance the Boats class (the class of boats and the things that are on a boat. usually people). The next constraint says that h and (b p) are each two types that satisfy the Houses constraint (the class of houses and things that are in houses in this case boats, but boats have things aboard them, so that has to be listed). 3. Haskell98 did not allow classes or instances with two type variables. FlexibleInstances and MultiParamTypeClasses remove that limitation, and they've been around for a very long time and will probably end up as part of the standard at some point. You can read about them here, along with other similar language features. http://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html#class-declarations On Mon, May 21, 2018 at 6:20 AM, PATRICK BROWNE <[hidden email]> wrote:
_______________________________________________ Beginners mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners |
David, Thanks for you clear and helpful answers. Pat On 21 May 2018 at 13:31, David McBride <[hidden email]> wrote:
This email originated from DIT. If you received this email in error, please delete it from your system. Please note that if you are not the named addressee, disclosing, copying, distributing or taking any action based on the contents of this email or attachments is prohibited. www.dit.ie Is ó ITBÁC a tháinig an ríomhphost seo. Má fuair tú an ríomhphost seo trí earráid, scrios de do chóras é le do thoil. Tabhair ar aird, mura tú an seolaí ainmnithe, go bhfuil dianchosc ar aon nochtadh, aon chóipeáil, aon dáileadh nó ar aon ghníomh a dhéanfar bunaithe ar an ábhar atá sa ríomhphost nó sna hiatáin seo. www.dit.ie Tá ITBÁC ag aistriú go Gráinseach Ghormáin – DIT is on the move to Grangegorman _______________________________________________ Beginners mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners |
Free forum by Nabble | Edit this page |