[Haskell-cafe] class-instance
Patrick Browne
patrick.browne at dit.ie
Mon Jan 17 18:15:11 CET 2011
A functional dependency seems to allow me to express my rather strange
requirement.
class Person i n | i -> n where
pid :: i
name :: i -> n
instance Person Int String where
pid = 1
name(1) = "john"
-- name(pid::Int) will produce john
Thanks for your help
Pat
On 17/01/2011 14:07, Patrick Browne wrote:
> On 17/01/2011 13:04, Ketil Malde wrote:
>>> So other PERSONs would have different types, say:
>
> I think the problem is there is just one constant p1 in the class and
> there needs to be multiple constants in the implementation (one for each
> person). It seems difficult to specify this using type classes So, some
> data declaration as you suggest will probably be needed.
>
> Thanks,
> Pat
>
>
>
> This message has been scanned for content and viruses by the DIT Information Services E-Mail Scanning Service, and is believed to be clean. http://www.dit.ie
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
This message has been scanned for content and viruses by the DIT Information Services E-Mail Scanning Service, and is believed to be clean. http://www.dit.ie
More information about the Haskell-Cafe
mailing list