Discussion:
Miranda - polymorphic functions
(too old to reply)
duke
2012-07-02 14:01:20 UTC
Permalink
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
2012-07-02 15:41:45 UTC
Permalink
In article <e204d4af-b0b3-456f-bf14-***@googlegroups.com>,
duke <***@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 <***@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
2012-07-02 16:33:41 UTC
Permalink
Post by Vincent Zweije
|| 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!
Continue reading on narkive:
Loading...