[Haskell-beginners] Understanding type variables in Haskell class declarations

PATRICK BROWNE patrick.browne at dit.ie
Mon May 21 10:20:53 UTC 2018


I am trying to understand how to interpret  type variables in Haskell class
declarations from a paper
<http://citeseerx.ist.psu.edu/viewdoc/download;jsessionid=1EA31D76684217BC728F916144BC6C38?doi=10.1.1.109.6853&rep=rep1&type=pdf>
.
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 <http://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 
<http://www.dit.ie/>

Tá ITBÁC ag aistriú go Gráinseach Ghormáin – DIT is 
on the move to Grangegorman <http://www.dit.ie/grangegorman>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20180521/2da1646c/attachment.html>


More information about the Beginners mailing list