[Haskell-cafe] Re: Newbie question

Alexander Seliverstov seliverstov.a at gmail.com
Mon Jan 21 12:28:33 EST 2008


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.

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?


2008/1/21, Jon Fairbairn <jon.fairbairn at cl.cam.ac.uk>:
>
> "Alexander Seliverstov" <seliverstov.a at gmail.com> writes:
>
> > How does caller choose which particular instance of Num they want?
>
> They specify the type... or just pass the result to
> something that specifies the type. Try it in ghci:
>
> Prelude> let f:: Integral i => Integer -> i; f = fromIntegral
> Prelude> let g :: Int -> Int; g = id
> Prelude> :t g (f 5)
> g (f 5) :: Int
> Prelude> let h :: Integer -> Integer; h = id
> Prelude> :t h (f 5)
> h (f 5) :: Integer
> Prelude>
>
> > What the difference between haskell class and interface in
> object-oriented
> > languge such Java or C#?
>
> Really they are completely different animals that look a lot
> alike because they serve similar purposes -- convergent
> evolution!
>
> --
> 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/cf98bc1f/attachment.htm


More information about the Haskell-Cafe mailing list