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
0
votes
1 answer

SML/ML Int to String conversion

I have this code: datatype 'a Tree = Empty | LEAF of 'a | NODE of ('a Tree) list; val iL1a = LEAF 1; val iL1b = LEAF 2; val iL1c = LEAF 3; val iL2a = NODE [iL1a, iL1b, iL1c]; val iL2b = NODE [iL1b, iL1c, iL1a]; val iL3 = NODE [iL2a, iL2b, iL1a,…
user494948
  • 51
  • 3
  • 9
0
votes
2 answers

Standard ML permutations

I am working on a function to the permutations for all values in a list. Here is what I have so far: //MY ROTATE FUNCTION fun rotate e [] = [[e]] | rotate e (x::xs)= (e::x::xs)::(List.map (fn l => x::l) (rotate e xs)); //MY CURRENT PERMUTATION…
user494948
  • 51
  • 3
  • 9
0
votes
1 answer

Write command-line arguments to file in SML

I am trying to write the command line arguments from my SML program into a file, each on a separate line. If I were to run sml main.sml a b c easy as 1 2 3 on the command line, the desired output would be to have a file with the…
Josue Espinosa
  • 5,009
  • 16
  • 47
  • 81
0
votes
1 answer

Understanding an SML type fn (f,g,x) => g(f(x)) or similar

Ok, sorry in advance this probably is repost but I spent a good 30 minutes searching stackoverflow and couldn't find something similar enough to understand. Basically, I don't understand why fn (f,g,x) => g(f(x)) gives the type (’a -> ’b)*(’b ->…
user5510766
0
votes
1 answer

Multiplying list1 by list2, getting "Warning: match nonexhaustive"

From what I've learned, fun addX (X, []) = [] | addX (X, y::ys) = (X + y :: addX(X, ys)); works perfectly fine, but when I try to multiply list1 by list2 with this method, it's giving me "Warning: match nonexhaustive", here's my code: fun…
chenchen
  • 49
  • 3
  • 6
0
votes
0 answers

How to use number as Variable in following code?

I am very new to SML-NJ. I am writing a code to add the values of Number1 and Number2 in SML-NJ. I want to use the GRAAL like data type definition in my code. Part - A : type Variable=string type Integer_constant=int I want to do something like…
0
votes
2 answers

How to access a tuple of tuples in SML?

I have this: val a = ((1,2),(1,2,1),(1,2,3),5,(4,5,6)); I need a function that returns few "x" is in this tuple... Example: Few "5" is in the tuple: funMagic (a,5); Must return 2 Help!
Neutron25
  • 11
  • 1
0
votes
1 answer

data constructor used without argument in pattern?

I'm not that familiar with SML but I have wrote the following program: datatype 'a bin_tree = Leaf of 'a | Node of 'a bin_tree * 'a bin_tree fun height Leaf (x) = 0 | height Node (l1,l2) = 1 + Int.max(l1,l2) fun is_balanced Leaf (x) = true | …
charwayne
  • 103
  • 1
  • 3
  • 18
0
votes
1 answer

SML/NJ Error in Command Prompt

So I installed SML/NJ in Windows 10 using the Windows Installer Package "smlnj-110.79", and following the instructions in this coursera video lecture, i should be able to open the command prompt and access sml by typing "sml". However, when I return…
A. Chiasson
  • 73
  • 1
  • 1
  • 6
0
votes
2 answers

how to stop a recursive function in this case (SML)

fun p(L) = [L] @ p( tl(L) @ [hd(L)] ); If L is [1,2,3] then I want to have a [ [1,2,3], [2,3,1], [3,1,2] ]. Since every time I append the first num to the end, then if L = [] then [] doesn't work here. How to stop the function once it has the…
Jam
  • 113
  • 2
  • 7
0
votes
1 answer

SMLNJ expand # in output

I have the following: val it = DATAX ("hello",DATAX ("world",DATAX #,DATAX #),... Is there a way to make the SMLNJ interpreter expand "#" so that I can see what the exact data is? Thanks!
minghan
  • 1,013
  • 7
  • 12
0
votes
1 answer

variable gets forgotten after print statement

Why does this compile? fun foo (h::t) = h = hd(t); But this does not fun foo (h::t) = PolyML.print (h::t); print "\n"; h = hd(t); ? Value or constructor (h) has not been declared Found near =( h, hd(t)) Value or constructor (t)…
lo tolmencre
  • 3,804
  • 3
  • 30
  • 60
0
votes
1 answer

print statement causing error?

The syntax in this language is confusing. fun bar a = print (Int.toString a); 0 compiles. No idea why emacs indents the 0 though. fun bar a = print (Int.toString a) 0 Throws an error. Error: operator is not a function [tycon mismatch] …
lo tolmencre
  • 3,804
  • 3
  • 30
  • 60
0
votes
1 answer

Editing tuples in a list of sml

I want to make a list which is of specification :(string*int) list and the tuples can be edited. For example, suppose val gamma = [("a",20),("b",30),("c",40)] :(string*int) list Now, how can I change the value 30 in the tuple ("b",30) to , let's…
Ankit Shubham
  • 2,989
  • 2
  • 36
  • 61
0
votes
1 answer

Can you formulate a case expression in a function that will accept the datatype cards and will return a boolean?

datatype cards = king of int * int | queen of string | jack of cards | ace of cards * cards | joker of int * cards