Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Miranda - polymorphic functions

26 views
Skip to first unread message

duke

unread,
Jul 2, 2012, 10:01:20 AM7/2/12
to
I'm working on understanding polymorphic functions, etc

Using the examples:
myfst (x,y) = x
g (x,y) = (-y,x)

I can see why myfst :: returns (*,**)-> *

However, I'm a little shaky with why g :: returns (*,num)->(num,*)

Is num in there, instead of the polytype **, because of the - operator is forcing that type on y?

Vincent Zweije

unread,
Jul 2, 2012, 11:41:45 AM7/2/12
to
In article <e204d4af-b0b3-456f...@googlegroups.com>,
duke <sidney.r...@gmail.com> wrote:

|| g (x,y) = (-y,x)

|| However, I'm a little shaky with why g :: returns (*,num)->(num,*)
||
|| Is num in there, instead of the polytype **, because of the - operator is
|| forcing that type on y?

Precisely; that's what type inference does for you.

Vincent.
--
Vincent Zweije <vin...@zweije.nl> | "If you're flamed in a group you
<http://www.xs4all.nl/~zweije/> | don't read, does anybody get burnt?"
[Xhost should be taken out and shot] | -- Paul Tomblin on a.s.r.

duke

unread,
Jul 2, 2012, 12:33:41 PM7/2/12
to
On Monday, July 2, 2012 9:41:45 AM UTC-6, Vincent Zweije wrote:
> In article <e204d4af-b0b3-456f...@googlegroups.com>,
> duke wrote:
>
> || g (x,y) = (-y,x)
>
> || However, I'm a little shaky with why g :: returns (*,num)->(num,*)
> ||
> || Is num in there, instead of the polytype **, because of the - operator is
> || forcing that type on y?
>
> Precisely; that's what type inference does for you.

Super! I think that I may begetting the hang of this functional stuff. :) I have zero formal CS background - just a self-taught, long-time, hobbyist hacker of a few imperative languages. So all this is new and strange to me. But it's all good! I'm now a little closer in grokking why Miranda keeps on barfing up that error message when I use the "show" function. Thanks!
0 new messages