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

Practice quesitions + solutions SML

239 views
Skip to first unread message

Maloo

unread,
Mar 8, 2007, 11:39:29 AM3/8/07
to
Hey guys,
Does anyone of you know of some resource on the internet with SML
practice questions along with solutions ?
It really helps.

thanks

TheGist

unread,
Mar 14, 2007, 6:06:54 PM3/14/07
to
In article <espe81$9cp$1...@wolfberry.srv.cs.cmu.edu>,
"Maloo" <ak.u...@gmail.com> wrote:

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

unread,
Mar 14, 2007, 6:07:40 PM3/14/07
to
I have some old workshop material containing exercises online (for
beginners and no longer maintained) at
http://www.kingston.ac.uk/~ku07009/MLWorkshop/start.html

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.

John Terrence

unread,
Jul 11, 2007, 5:14:20 PM7/11/07
to
In <et9rnc$6op$1...@wolfberry.srv.cs.cmu.edu> Chris Reade wrote:
> I have some old workshop material containing exercises online (for
> beginners and no longer maintained) at
> http://www.kingston.ac.uk/~ku07009/MLWorkshop/start.html
>
> Chris Reade
> On 8 Mar 2007, at 02:46, Maloo wrote:

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.

Chris Reade

unread,
Jul 13, 2007, 1:38:03 PM7/13/07
to
John

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

JT

unread,
Aug 20, 2007, 8:49:53 AM8/20/07
to
Chris Reade escreveu:

> John
>
> 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.


Torben Ægidius Mogensen

unread,
Aug 21, 2007, 10:47:22 AM8/21/07
to
JT <j...@nowherenow.com> writes:

> 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


0 new messages