672 questions
107
votes
2
answers
21k
views
What are the differences between SML and OCaml? [closed]
What sets the two ML dialects apart?
44
votes
3
answers
5k
views
What's the difference (if any) between Standard ML's module system and OCaml module system?
My question is if there is any difference between Standard ML's module system and OCaml module system? Has OCaml all the support of functors , ascriptions etc... that SML has?
38
votes
1
answer
4k
views
If SML.NET had functors why can't F#?
This question started out from
My translating of "ML for the Working Programmer" (WorldCat) by L. C. PAULSON to F# which uses functors for the examples.
Eventual desire to translate "Purely ...
29
votes
6
answers
25k
views
ML IDE and Compiler for Windows or Linux or Mac
I have to write some code in ML and it is my first time I`m going to use the language.
Is there any Development Environment for Standard ML? (preferably under Windows). I tried googling but all I ...
28
votes
1
answer
4k
views
Growth of Type Definition in SML Using Hindley Milner Type Inference
Someone once showed me a little 'trick' in SML where they wrote out about 3 or 4 functions in their REPL and the resulting type for the last value was extremely long (like many page scrolls long).
...
25
votes
2
answers
2k
views
Inferred type appears to detect an infinite loop, but what's really happening?
In Andrew Koenig’s An anecdote about ML type inference, the author uses implementation of merge sort as a learning exercise for ML and is pleased to find an “incorrect” type ...
18
votes
1
answer
4k
views
When to use semicolons in SML?
I know that semicolons are used as terminators in REPL. But I'm confused about when to use them in a source file.
For example it is not necessary after val x = 1. But if I omit it after use "foo.sml",...
16
votes
3
answers
6k
views
Is the SML `o` operator only useful on single-argument functions?
Is the o composition operator (eg. val x = foo o bar, where foo and bar are both functions), only usable on single-argument functions and/or functions with equal numbers of arguments? If not, what is ...
14
votes
1
answer
1k
views
Church-Rosser Theorem Example in a Functional Programming Language
I have seen multiple references to the Church Rosser theorem, and in particular the diamond property diagram, while learning functional programming but I have not come across a great code example.
If ...
12
votes
3
answers
9k
views
Standard ML functor examples
Functors in Standard ML are related to the module system and can generate structures based on other structures. An example of a functor generating list combinators for various types of lists is given ...
11
votes
2
answers
3k
views
OCaml - Pattern matching with list reference in a tuple
is there a cleaner way of doing this? I'm trying to do pattern matching of a
(a' option * (char * nodeType) list ref
the only way I found was doing this :
match a with
| _, l -> match !l with
...
11
votes
1
answer
2k
views
Examples of the difference between `prompt/control` and `shift/reset`
I am not sure I understand the difference between the delimited continuation operator pairs prompt/control and reset/shift. I understand some basic examples of use, but in those examples their ...
10
votes
3
answers
4k
views
GUI for Standard ML?
I started learning Standard ML recently out of curiosity. So what I know is that is has an efficient compiler (MLton) which allows us to freely use abstractions without worrying about performance.
It ...
9
votes
4
answers
9k
views
Pattern matching functions in OCaml
Can everyone explain to me this piece of code ?
let safe_division n = function
| 0 -> failwith "divide by 0"
| m -> n / m
When I excute safeDiv 3 0 , what is the m and n in this case ?
In ...
9
votes
3
answers
2k
views
Understanding the type error: "expected signature Int*Int->Int but got Int*Int->Int"
The comments on Steve Yegge's post about server-side Javascript started discussing the merits of type systems in languages and this comment describes:
... examples from H-M style systems where you ...
9
votes
1
answer
1k
views
Inferring recursive expressions using Hindley Milner & constraints
I am trying to infer the type of the following expression:
let rec fix f = f (fix f)
which should be given the type (a -> a) -> a
After using the bottom up algorithm (described in generalizing ...
9
votes
0
answers
822
views
Which languages, if any, implement rank-2 parametric polymorphism and why not ML?
In section 23.8 of his book Types and Programming Languages, Benjamin C. Pierce writes the following:
Another well-studied restriction of System F is rank-2 polymorphism, introduced by Leivant (1983)...
8
votes
2
answers
584
views
Do ML family compilers do any sophisticated optimization for tail calls?
I (believe) the following function definition is tail-recursive:
fun is_sorted [] = true
| is_sorted [x] = true
| is_sorted (x::(y::xs)) =
if x > y
then false
else is_sorted (...
8
votes
2
answers
2k
views
Lexical Scope in Python vs ML
I'm in a big dilemma, take the following code written in ML:
val x = 1
fun f(y) = x + y
val x = 2
val y = 3
val z = f (x + y)
The value of z is 6. Now if I write the same code in python the value of ...
8
votes
1
answer
845
views
How to understand segmented binomial heaps described in <Purely Functional Data Structures>
In chapter 6.3.1 of the thesis Purely Functional Data Structures, says:
Then, whenever we create a new tree from a new element and a segment
of trees of ranks 0... r-1, we simply compare the new ...
7
votes
4
answers
6k
views
return a list of element from a list in OCaml
I am new to OCaml, and I am now trying to implement a function that returns a list of elements of a given list x at indexes in list y.
For example, that function should perform the following ...
7
votes
2
answers
2k
views
Example of nested signatures in OCaml?
In OCaml, you can nest signatures:
module type FOO =
sig
module type BAR
(* … *)
end
I was just wondering if anyone had any examples of this in use, since I can’t think of any places where it ...
7
votes
1
answer
394
views
Encode rank-2 polymorphism equivalent in SML
runST is a Haskell function that statically constrains the usable lifetime of a resource through types. To do this it uses rank-2 polymorphism. Standard ML's simpler type system only offers rank-1 ...
6
votes
3
answers
3k
views
Standard ML repeat last command, left arrow?
I am learning standard ML using its interpreter. Sometimes I make typo and just want to repeat the previous command like in Linux shell. However, up arrow will end up with printing special characters ...
6
votes
4
answers
484
views
Is there a standard higher order function for applying a transformation several times?
I'm thinking of a function like this:
> let applyN (initial : 't) (n:int) (f : 't -> 't) = seq {1..n} |> Seq.fold (fun s _ -> f s) initial;;
val applyN : initial:'t -> n:int -> f:('...