2,099
questions
106
votes
2
answers
21k
views
What are the differences between SML and OCaml? [closed]
What sets the two ML dialects apart?
80
votes
8
answers
39k
views
Haskell or Standard ML for beginners? [closed]
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 ...
75
votes
9
answers
21k
views
Explaining pattern matching vs switch [closed]
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 ...
61
votes
3
answers
3k
views
What are the primary theoretical difficulties with adding ML-style modules to Haskell?
It is well known that Haskell-style typeclasses and ML-style modules offer different mechanisms for specifying interfaces. They are (possibly) equivalent in power, but in practice each has their own ...
52
votes
1
answer
11k
views
SML-NJ, how to compile standalone executable
I start to learn Standard ML, and now I try to use Standard ML of New Jersey compiler.
Now I can use interactive loop, but how I can compile source file to standalone executable?
In C, for example, ...
43
votes
3
answers
4k
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?
41
votes
1
answer
4k
views
Encoding Standard ML modules in OO
The ML module system stands as a high-water mark of programming language support for
data abstraction. However, superficially, it seems that it can easily be encoded in an object-oriented language ...
40
votes
1
answer
16k
views
Warning: calling polyEqual
Can somebody please explain, what does this warning means?
stdIn:18.35 Warning: calling polyEqual
and why do I have "a and not 'a in the following statement:
val alreadyVisited = fn : ''a * ''a ...
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 ...
30
votes
5
answers
2k
views
Can good type systems distinguish between matrices in different bases?
My program (Hartree-Fock/iterative SCF) has two matrices F and F' which are really the same matrix expressed in two different bases. I just lost three hours of debugging time because I accidentally ...
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 (and ...
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).
...
28
votes
1
answer
6k
views
(ML) Modules vs (Haskell) Type Classes
According to Harper (https://existentialtype.wordpress.com/2011/04/16/modules-matter-most/), it seems that Type Classes simply do not offer the same level of abstraction that Modules offer and I'm ...
27
votes
2
answers
5k
views
How to 'fix' the SML/NJ interactive system to use Arrow Keys
I'm having some trouble using SML/NJ interactive system, namely, that when I try to use my arrow keys (either left or right to make a correction in the expression I've typed, up to repeat the last ...
26
votes
4
answers
7k
views
Functional Breadth First Search
Functional depth first search is lovely in directed acyclic graphs.
In graphs with cycles however, how do we avoid infinite recursion? In a procedural language I would mark nodes as I hit them, but ...
26
votes
3
answers
27k
views
Line Comments in Standard ML
I'm learning ML, with the SML/NJ dialect. What I'm trying to figure out is if there is a line comment operator. I found the block comment operator, (* ... *), but I really miss line comments.
...
25
votes
1
answer
951
views
What, if anything, do you need to add to a dependent type system to get a module system?
Dependent type systems seem to support some of the uses of a ML module system. What do you get out of a module system that you do not get out of dependent records?
module ~ record
signature ~ record ...
24
votes
1
answer
14k
views
How can I load a ml file in toplevel of OCaml, just like `use mine.sml` in SML/NJ?
In SML's repl, you can just type use whatever.sml and load all things inside that .sml into repl.
How can I do that in OCaml?
23
votes
2
answers
2k
views
What are the limits of type inference?
What are the limits of type inference? Which type systems have no general inference algorithm?
21
votes
3
answers
14k
views
Curried anonymous function in SML
I have the function below and it works:
(fn x => x * 2) 2;
but this one doesn't work:
(fn x y => x + y ) 2 3;
Can anyone tell me why? Or give me some hint to get it to work?
20
votes
7
answers
9k
views
What is SML used for? [closed]
What are the uses of SML in the real word?
Are its practical uses similar to that of Prolog?
19
votes
3
answers
7k
views
Nested case statements in SML
This is more of a stylistic question than anything else. Given the following piece of code:
case e1 of (* datatype type_of_e1 = p1 | p2 *)
p1 => case e11 of (* ...
19
votes
3
answers
3k
views
Is there a Haskell/ML-like compiler to C?
People have written games for the iPhone in Scheme. Because (some) Scheme-compilers compile down to C, it was easy to mix with Objective-C and integrate with XCode.
I am aware of patches for Haskell ...
18
votes
3
answers
10k
views
SML: difference between type and datatype
I'm pretty new at SML and I would like to make sure I really know the basics. What is the difference between type and datatype in SML, and when to use which?
18
votes
1
answer
941
views
How do functional languages represent algebraic data types in memory?
If you were writing a bioinformatics algorithm in Haskell, you'd probably use an algebraic data type to represent the nucleotides:
data Nucleotide = A | T | C | G
You'd do similarly in Standard ML ...
17
votes
1
answer
6k
views
Increasing the print depth in SML/NJ
I'm trying to get SML/NJ to print out a result at the top level without
putting # signs everywhere.
According to some old docs (and a post to this newsgroup on 2001), it
should be possible to use ...
17
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",...
17
votes
2
answers
3k
views
SML: What's the difference between using abstype and using a signature to hide the implementation of a structure?
I've done a little work in SML in the past, but I'm now starting to get to the more interesting parts.
Using the abstype...with...end construct, I can make things but keep their implementation ...
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 ...
15
votes
3
answers
2k
views
Statically "extend" a record-ish data type without indirection hassle
I am currently working with a three-level process for which I need some information to flow being accessed and updated. The information is also three-leveled, in such a way that a process at one level ...
15
votes
1
answer
2k
views
Why SML and OCaml are considered as dialects of ML? What is the definition of ML?
There are many dialects of ML, and SML and OCaml are most popular ones. There're many differences between SML and OCaml, but they are both considered as dialects of ML.
So,
Why SML and OCaml are ...
15
votes
1
answer
9k
views
How to convert negative integers to strings in SML with minus sign instead of tilde?
The standard SML library function Int.toString prefixes negative numbers with ~ instead of -. Is there a library function to use - instead, short of writing
fun i2s i =
if i < 0 then "-" ^ ...
14
votes
2
answers
10k
views
Difference between "local" and "let" in SML
I couldn't find a beginner friendly answer to what the difference between the "local" and "let" keywords in SML is. Could someone provide a simple example please and explain when one is used over the ...
13
votes
4
answers
8k
views
Recursive anonymous functions in SML
Is it possible to write recursive anonymous functions in SML? I know I could just use the fun syntax, but I'm curious.
I have written, as an example of what I want:
val fact =
fn n => case n ...
13
votes
4
answers
6k
views
Do Python's scoping rule fit the definition of lexical scoping? [duplicate]
According to my programming language class, in a language that uses lexical scoping
The body of a function is evaluated in the environment where the
function is defined, not the environment where the ...
12
votes
1
answer
17k
views
Understanding foldl in ML
I need to write a function that takes a list of strings and finds the largest string in the list. The catch is it needs to iterate through the list using List.foldl and cannot use recursive calls ...
12
votes
1
answer
6k
views
SML Warning: Type Vars Not Generalized when using Empty Lists or NONE option
I can't for the life of me figure out why the following SML function is throwing a Warning in my homework problem:
fun my_func f ls =
case ls of
[] => raise MyException
| head :: rest =&...
12
votes
1
answer
15k
views
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 ...
12
votes
1
answer
1k
views
Pattern match in binding of lambda?
In Haskell, I often do something like this:
f $ \x -> case x of
A a1 a2 -> ...
B b1 b2 -> ...
C c1 c2 -> ...
But I don't want x, I just want to ...
12
votes
3
answers
8k
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 ...
12
votes
2
answers
1k
views
Does Standard ML support Unicode?
Does Standard ML support Unicode?
I believe it does not but cannot find any authoritative documentation for SML stating such.
A yes or no is all that is needed, but you must know for a fact. No ...
12
votes
1
answer
38k
views
how do I add a line break in a string?
The question is in the title.
If I do this in the REPL (SML/NJ in windows commandline)
val x = "hello\nworld";
I'd expect
val x = "hello
world" : string
or something similar, but I get
val x = ...
11
votes
3
answers
6k
views
Run SML file but not be left in interactive mode
I am using New Jersey SML on Windows. If test.sml is an SML file I can execute it by running this at a Windows command prompt:
C:\> sml test.sml
I then get the usual SML output and a new SML ...
11
votes
5
answers
12k
views
Standard sorting functions in SML?
Are there standard sorting functions in SML? The documentation on the Internet is so scarce I couldn't find any.
11
votes
3
answers
2k
views
Do OCaml 'underscore types' (e.g. '_a) introduce the possibility of runtime type errors / soundness violations?
I was reading a little bit about the value restriction in Standard ML and tried translating the example to OCaml to see what it would do. It seems like OCaml produces these types in contexts where SML ...
11
votes
2
answers
5k
views
Problem running smlnj under OSX 10.6
I downloaded and installed the SML NJ implementation using the DMG for x86 from here :
http://smlnj.cs.uchicago.edu/dist/working/110.72/index.html
However when I open a terminal window and go to /usr/...
11
votes
1
answer
5k
views
In SML, how to assert that a particular exception is thrown?
Without taking the effort to actually clone JUnit or something, I'm throwing together a few utility functions to help test some SML code. I do know about QCheck, but it can't do this one thing either ...
11
votes
1
answer
1k
views
Printing only print output with SML/NJ
I'm trying to use SML/NJ, and I use sml < source.sml to run the code, but it prints out too much information.
For example, this is the source.sml:
fun fac 0 = 1
| fac n = n * fac (n - 1)
val r ...
11
votes
1
answer
1k
views
What is the difference in capability between the SML module system and Haskell's Type and Typeclass system?
I'm trying to understand where the shortcoming is here. Does the SML Module system merely provide dependent types, similar to how Idris has extended the Haskell type system, or is there more going on ...
10
votes
2
answers
12k
views
SML How to check variable type?
Is there any way to check/test the type of a variable?
I want to use it like this:
if x = int then foo
else if x = real then bar
else if x = string then ...
else .....