Questions tagged [smlnj]

Standard ML of New Jersey (SML/NJ)

SML/NJ is a popular implementation of the Standard ML programming language that was co-developed jointly by Bell Laboratories and Princeton University. It is released under a BSD like license.

References:

Wiki page

866 questions
4
votes
2 answers

How to clear SML Buffer in Emacs when using SML mode.

I am using Emacs with SML mode. Sometimes I need to clean the SML buffer. How can I do that.
rookie
  • 7,723
  • 15
  • 49
  • 59
4
votes
1 answer

What is difference between rem and mod function in sml?

I'm working on sml project in which I have to implement these two function rem & mod for custom datatype. I know the definition of remainder rem. dividend = divisor * quotient + remainder What is the definition of mod? Please explain me the…
LearningGiraffe
  • 145
  • 3
  • 11
4
votes
1 answer

Query the SML/NJ REPL for signatures or structures?

Is there a way to get a list of the signatures or structures available in the top-level environment from the SML/NJ REPL? I'm looking to get a listing of the signatures/structures that appear to be defined in the sources.cm files in the sml source…
Rorschach
  • 31,301
  • 5
  • 78
  • 129
4
votes
1 answer

Match non exhaustive in sml

fun p( x::xl ) = if x::xl = [] then [] else [0]; It received a Warning: match non exhaustive. x::xl => ... What I want to do is: p( [] ) = [] When I do this, it gives a uncaught exception Match [nonexhaustive match failure]
Jam
  • 113
  • 2
  • 7
4
votes
2 answers

I want to make function maptree with standard ML

I want to make function maptree with standard ML. If function f(x) = x + 1; then maptree(f, NODE(NODE(LEAF 1,LEAF 2),LEAF 3)); should make result NODE(NODE(LEAF 2,LEAF 3),LEAF 4)) I write the code like below. datatype 'a tree = LEAF of 'a | NODE…
kor_dreamer
  • 107
  • 6
4
votes
2 answers

right-hand-side of clause doesn't agree with function result type

Write a function remove_option, which takes a string and a string list. Return NONE if the string is not in the list, else return SOME xs where xs is identical to the argument list except the string is not in it. You may assume the string is in the…
Slark
  • 43
  • 4
4
votes
1 answer

Can you disable all print statements in SML

I currently have a lot of print statements in SML code, and I'm traversing a very large tree, so it takes a while for all the print statements to be printed, but right now I don't want to see any print statements and just want to see it run as fast…
rasen58
  • 4,672
  • 8
  • 39
  • 74
4
votes
3 answers

(SML) Defining a type as a function and creating a function of this type

First question here and just want to preface that I did several queries and while I found multiple questions that were worded similarly I found none that were asking, or answering, the question I have (as far as I can tell). I'm working in SML on an…
vitaFrui
  • 53
  • 4
4
votes
3 answers

SML/NJ - One line length function using foldr

I'm trying to create a length function, similar to the one already included in ML. My restrictions are that it has to be done on one line and use either map, foldl, or foldr. Right now my line of code looks like this: val mylength = foldr ( fn(x,y)…
4
votes
1 answer

What do "continuations" mean in functional programming?(Specfically SML)

I have read a lot about continuations and a very common definition I saw is, it returns the control state. I am taking a functional programming course taught in SML. Our professor defined continuations to be: "What keeps track of what we still have…
Ralph
  • 2,959
  • 9
  • 26
  • 49
4
votes
2 answers

SML/NJ: getting user input

How do I prompt for user input while a function is running?
john
  • 41
  • 1
  • 2
4
votes
1 answer

smlnj interactive system: fatal error

Getting a strange error on my Crouton chroot on my Chromebook after apt-get install smlnj and attempting to call sml from the terminal, an error that I haven't been able to find anywhere else: $ sml /usr/lib/smlnj/bin/sml: Error -- unable to map…
jayelm
  • 7,236
  • 5
  • 43
  • 61
4
votes
1 answer

SML-NJ List Equals Nil vs Null List

I have a question about the way SML of New Jersey interprets lists: Suppose I have a function f(x : 'a, n : int) : 'a list such that f returns a list of n copies of x, e.g. f(2,5) = [2,2,2,2,2], f(9,0) = []. So then I go into the REPL, and I check…
Newb
  • 2,810
  • 3
  • 21
  • 35
4
votes
1 answer

Polymorphic function as return value and value restriction in SML

Basically, I want to have a function to return a polymorphic function, some thing like this: fun foo () = fn x => x So the foo function takes in a value of type unit and returns a polymorphic identity function and the compiler is happy with…
sxu
  • 551
  • 4
  • 14
4
votes
4 answers

Different fold in Haskell and SML/NJ

In foldl definition possible wrong in SML/NJ 110.75, I found that the relation foldl (op -) 2 [1] = foldr (op -) 2 [1] holds. But when I tried the above in Haskell I found that the above relation rewritten in Haskell as foldl (-) 2 [1] == foldr (-)…
Dragno
  • 3,027
  • 1
  • 27
  • 41