sml

prototyping functions in SML

I have two functions, f and g, which call each other recursively. Unfortunately, when f calls g, it has not yet been declared, so I get an "unbound variable" error. How can I prototype (or whatever the equivalent vocabulary is) this function in SML/NJ? ...

How do I use the Queue library in SML/NJ

I see that the SML/NJ includes a queue structure. I can't figure out how to use it. How do I use the additional libraries provided by SML/NJ? ...

Explaining pattern matching vs switch.

I have been trying to explain the difference between switch statements and pattern matching(F#) to a couple of people but I haven't really been able to explain it well..most of the time they just look at me and say "so why don't you just use if..then..else". How would you explain it to them? EDIT! Thanks everyone for the great answers...

What is a good book or tutorial on Standard ML?

What is a good book or tutorial on Standard ML? ...

SML comparing files at the bit level

I am attempting to compare files in a directory using SML. Using the TextIO library is fairly easy but I need to compare the files at the bit level. That is, a binary compare. I am using a function similar to this: fun listDir (s) = let fun loop (ds) = (case OS.FileSys.readDir (ds) of "" => [] before OS.FileSys.closeDir (ds)...

How can I print polymorphic values in Standard ML?

Is there a way to print polymorphic values in Standard ML (SML/NJ specifically)? I have a polymorphic function that is not doing what I want and due to the abysmal state that is debugging in SML (see Any real world experience debugging a production functional program?), I would like to see what it is doing with some good-ol' print's. A...

What are the differences between SML and Ocaml?

What sets the two ML dialects apart? ...

What is SML used for?

Hello everyone, What are the uses of SML in the real word? Are its practical uses similar to that of Prolog? ...

How can I customize the SML/NJ interactive loop?

I'm new to Standard ML and I'm trying to get my head around the SML/NJ runtime environment. I want to adapt it to my needs. Specifically, I want to: Use IntInf by default Prevent it from truncating strings and IntInf to 70 characters. Here's what I've found in my 8+ hours reading documentation and experimenting. I can overload IntIn...

How do you print inside a case statement in SML?

I'm just starting out with SML, and I'm trying to modify some code so I understand what it's doing (I can't find a decent SML/NJ debugger, but that's a separate question). fun type_check e theta env non_gens = case e of constant_int _ => (integer,theta) | constant_bool _ => (boolean,theta) | ... Assume this is valid co...

How to coerce a type in SML (like casting)

I'm creating a structure of Rationals (int * int) and one of my functions is: fun diff ((n, d), (n', d')) = let val (top, bot) = sum ((n, d), (~n', d')) in (top / gcd(top, bot), bot / gcd(top, bot)) end gcd gives me the greatest ...

SML function call doesn't parse arguments as arguments

I'm getting what seems to be a precedence issue in calling an SML function, substitute: fun substitute v new (typevar q) = ... And I am calling this from another function: fun new_type_vars (typevar v) non_gens = substitute v new_var() (typevar v) But I get an error: C:/sml/type_checker.sml:22.48-23.44 Err...

How do I print type information in SML?

After a command is executed in SML, "it" is returned which has the data and the type returned from the command. For example: false; val it = false : bool Let's say I have a binding in a program like so: val argsToOutput = (map (fn (Absyn.var_exp(n)) => (lookupReference env n)) exps) Is there a w...

Haskell or Standard ML for beginners?

I'm going to be teaching a lower-division course in discrete structures. I have selected the text book Discrete Structures, Logic, and Computability in part because it contains examples and concepts that are conducive to implementation with a functional programming language. (I also think it's a good textbook.) I want an easy-to-underst...

Loops in SML/NJ

I'm very new to SNL/NJ and was wondering how I could accomplish the following: foo(stuff,counter) { while(counter > 0) { bar(stuff); counter-1; } return; } Something like this, but how do I decrement?: foo(stuff,counter) = while counter > 0 do bar(stuff) ??? // how do I decrement counter here? ...

Functional: construct a list of integers 1..n

This is not homework. I'm learning Standard ML on my own. I know a bit of Scheme, too, so this question ought to be answerable in either language. My self-imposed assignment is to write a function that constructs a list of integers from 1 to n. For example, list(7) should return [1,2,3,4,5,6,7]. An O(n) solution would be ideal. It's ea...

Using ML in "Real-World" Applications

I really liked learning ML at college. I find functional programming often a refreshingly elegant way to write certain algorithms. I have heard of F# and played around with that a bit. Still, I've written some interesting functions in ML and would like to integrate them as libraries I could use in other applications. Usually I paste ...

Doing a N-dimensional walk in pure functional ML ?

The idea is to walk over multiple dimensions, each one defined as a range (* lower_bound, upper_bound, number_of_steps *) type range = real * real * int so functions like fun foo y x or fun foo z y x could be applied to the whole square X*Y or cube X*Y*Z. SML/NJ doesn't like my implementation below : test2.sml:7.5-22.6 Error: right-...

ensuring a specific type outcome in SML

Hi Im trying to make a function that will return an element of type "point": type point = {x : int, y : int}; fun pointadd (p1: point, p2: point) = (((#x p1) + (#x p2)), ((#y p1) + (#y p2))); but SMLNJ doesn't seem to understand my intention that the result should be of type "point" as well: use "test1.sml"; [opening test1.sml] type...

BigInt for Standard ML/NJ

Is there a Java BigInt equivalent for Standard ML? The normal int type throws an exception when it overflows. ...