[Haskell-cafe] Re: Newbie question

Alexander Seliverstov seliverstov.a at gmail.com
Mon Jan 21 14:09:33 EST 2008


Thanks. I get it.



2008/1/21, Jon Fairbairn <jon.fairbairn at cl.cam.ac.uk>:
>
> "Alexander Seliverstov" <seliverstov.a at gmail.com> writes:
>
> > So, the function type "(Num a)=>Integer->a" means that return value of
> > this function can be cast to any particular instance of class Num.
>
> For some meanings of the word "cast" yes. I'd rather say
> "f:: Num a=> Integer -> a" means that for any type a that is
> an instance of Num, given an integer f will return a member
> of that type.
>
> > Ok. I have a my own class "class A a" and want to write function like
> > this  "f:: (A a)=>Integer->a". Can I do it?
>
> You need to be a bit more specific about what f is supposed
> to do without that, I can answer unequivocally yes, and give
> you
>
> f:: (A a) => Integer -> a
> f n = undefined
>
> :-P
>
> But in general you are going to want something a bit more
> useful, which means that you have to have a path from
> Integer to a -- what the path can be is depends on what
> "methods" you give class A. For example:
>
> class A a where
>   first_a :: a
>   second_a :: a
>
> f :: A t => Integer -> t
> f n | odd n = first_a
>     | otherwise = second_a
>
> --
> J¨®n Fairbairn                                 Jon.Fairbairn at cl.cam.ac.uk
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>



-- 
§³ §å§Ó§Ñ§Ø§Ö§ß§Ú§Ö§Þ,
§³§Ö§Ý§Ú§Ó§Ö§â§ã§ä§à§Ó §¡§Ý§Ö§Ü§ã§Ñ§ß§Õ§â
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080121/ef68d3d3/attachment.htm


More information about the Haskell-Cafe mailing list