thanks
I would recommend picking up Ullman's book.
http://www.amazon.com/Elements-ML-Programming-ML97-2nd/dp/0137903871
The book is very good and has lots of excercises to try.
Solutions are available from the author's website so you can check your
solutions.
Chris Reade
On 8 Mar 2007, at 02:46, Maloo wrote:
> Hey guys,
> Does anyone of you know of some resource on the internet with SML
> practice questions along with solutions ?
> It really helps.
>
> thanks
>
>
>
> This email has been scanned for all viruses by the MessageLabs Email
> Security System.
Hi Chris Reade !
Sorry to hijack a thread like this, but asked a question about your book
"EFP" in another thread.
fun f1 (x,y,z) = (x,y,1) fun f2 (x,y,z) = (x,y,z * x) fun f3 (x + 1, y,
z) = (x + 1, y, z)
val body = f3.f2
goes crazy on SML-NJ:
Standard ML of New Jersey v110.60 [built: Sun Nov 12 17:21:48 2006]
- [
opening /tmp/sml18216PQH]
/tmp/sml18216PQH:5.5-5.37 Error: non-
constructor applied to argument in pattern: +
/tmp/sml18216PQH:5.25
Error: unbound variable or constructor: x
/tmp/sml18216PQH:6.12-6.17
Error: unbound structure: f3 in path f3.f2
uncaught exception Error
raised at: ../compiler/TopLevel/interact/evalloop.sml:63.48-63.56
../
compiler/TopLevel/interact/evalloop.sml:44.55
../compiler/
TopLevel/interact/evalloop.sml:291.17-291.20
- f2; stdIn:1.1-1.3 Error:
unbound variable or constructor: f2
- f1; stdIn:1.1-1.3 Error: unbound
variable or constructor: f1
- body; stdIn:1.1-1.5 Error: unbound
variable or constructor: body
-
I'm using sml-mode.
Can you help?
Thanks in advance.
JT.
In the "EFP" book a small circle is used for composition with an
explanation that this is written as a lower case o in ML (not a dot).
Also the definition in the book is not as you have written it. It
should be:
fun f1 (x,y,z) = (x,y,1)
fun f2 (x,y,z) = (x,y,z * x)
fun f3 (x, y,z) = (x + 1, y, z)
val body = f3 o f2
Chris Reade
Hi --
Upon evaluating this, an error crops up. I have no idea as to what it
means.
- fun f1 (x,y,z) = (x,y,1);
val f1 = fn : 'a * 'b * 'c -> 'a * 'b * int
- fun f2 (x,y,z) = (x,y,z*x);
val f2 = fn : int * 'a * int -> int * 'a * int
- fun f3 (x,y,z) = (x + 1, y, z);
val f3 = fn : int * 'a * 'b -> int * 'a * 'b
- val body = f3 o f2;
stdIn:5.5-5.19 Warning: type vars not generalized because of
value restriction are instantiated to dummy types (X1,X2,...)
val body = fn : int * ?.X1 * int -> int * ?.X1 * int
This must have something to do with the newer SML 97 standard.
Any help is appreciated.
JT.
> Chris Reade escreveu:
>> fun f1 (x,y,z) = (x,y,1)
>> fun f2 (x,y,z) = (x,y,z * x)
>> fun f3 (x, y,z) = (x + 1, y, z)
>> val body = f3 o f2
> Upon evaluating this, an error crops up.
>
> - val body = f3 o f2;
> stdIn:5.5-5.19 Warning: type vars not generalized because of
> value restriction are instantiated to dummy types (X1,X2,...)
> val body = fn : int * ?.X1 * int -> int * ?.X1 * int
>
> This must have something to do with the newer SML 97 standard.
It does indeed. SML 97 restricts non-values in val bindings to
monomorphic to avoid problems with polymorphic references. Since the
expression f3 o f2 is not a value, it is not generalized (made
polymorphic). To get around the problem, you can eta-expand the
expression:
val body = fn arg => (f3 o f2) arg
which reduces to
val body = fn arg => f3 (f2 arg)
or, even simpler,
fun body arg = f3 (f2 arg)
Torben