875 questions
2
votes
1
answer
66
views
SML Quicksort Recursive Calls
I have a question regarding the following code I found on github:
fun quicksort nil = nil
| quicksort (pivot :: rest) =
let
fun split(nil) = (nil,nil)
| split(x :: xs) =
...
1
vote
1
answer
102
views
Why is semicolon required in this single line Standard ML code: Int.toString 5?
I have a file foo.sml with a single line of Standard ML code:
Int.toString 5
This runs fine in SML/NJ but not in MLton:
$ cat foo.sml
Int.toString 5
$ sml < foo.sml
Standard ML of New Jersey (64-...
1
vote
0
answers
43
views
Use external SML file in SML/NJ build configuration
I have this configuration that works but my attempt to use an external file use "external.file"; in the functor failed. I wanted to test an external file by calling the functions in the ...
0
votes
0
answers
145
views
Error "no *.cm, *.mlb, or millet.toml files found in this directory" in VS code using SML
I installed WSL, SML and Millet extensions in VS code for a course I'm taking, I have 2 files with code when I'm trying to run them I get an error:
"uncaught exception SysErr [SysErr: access: ...
2
votes
2
answers
90
views
Error: unbound type constructor: TypeInteger
Updated Code:
val changeTypeMapTable =
fn (x: TypeMapTable) =>
fn (a: Variable, Type_Integer) =>
(fn (y: Variable) =>
if y = a then ...
0
votes
4
answers
484
views
How to add all elements in a list in SML
I am trying to add all elements in a given integer list and finally return an integer as its sum
Following is the code I have tried
val intList = [1,2,3,4];
fun addList (list) =
let
val head = ...
1
vote
1
answer
72
views
SML: Error: types of rules don't agree when I open the Real signature
I am having this mysterious problem. I have this function in a file:
fun sum _ nil acc = (Real.fromInt acc)
| sum x (hd::tl) acc =
if x=hd orelse toUpper x=hd then sum x tl (acc+1)
...
1
vote
1
answer
90
views
Multiplying real number extracted of a pair using case of in StandarML
I create a datatype and a function. The function must be able to do a multiplication according to whether the members of the pair are int(s) or real(s). I can get to work for Int, but when I add a ...
1
vote
1
answer
65
views
Error while using HashTable structure in files used in a CM file
I am using a CM file "build.cm" to compile my sml files. In the file symbol_table.sml, I have used the structure HashTable from the sml basis library. When the CM file is run, I receive an ...
0
votes
2
answers
41
views
In SML - Why doesn't simple recursion always return 0 if first expression met?
In a simple recursion with first if expression true then 0. if steps in the recursion keeps going until that first expression is true, why isn't 0 always returned?
fun stepping (n : int, number : ...
0
votes
1
answer
85
views
SML using destructors gives deleting INT0 LPAREN
The following function is using pattern matching.
fun f (x,0) = x
| f (0,y) = y
| f (x,y) = x+y;
I want to write this using if-else. This function of mine works fine:
fun f1(x, y) =
if y = 0 ...
0
votes
2
answers
45
views
Currying and summation of two lists of varying size
I'm self-learning SML and am currently am stuck with the concept of recursion between two lists of varying sizes.
Suppose you have two int lists of varying size, and a function that multiplies two ...
1
vote
1
answer
128
views
Generate a Real list from a Int list in SML
Hello every body im training some SMLs and im creating a code to get deviation of a int list . in the process of it , i need to get a Real list out of some numbers in a int list , which it doesnt let ...
1
vote
0
answers
96
views
Types of Rules Don't Agree
I'm trying to write a program in SML for the following problem:
A game is played with a card-list and a goal. The player has a list of held-cards, initially empty. The player
makes a move by either ...
1
vote
3
answers
302
views
Sum two list in sml
There are two list in sml and I want to add one to another
val one = [1.1,2.2,3.3] : real list;
val two = [4.4,5.5,6.6] : real list;
The result should be [5.5, 7.7, 9.9].
I not sure I'm doing this ...
1
vote
1
answer
180
views
SML Uncaught exception Empty homework1
Question: Write a function number_before_reaching_sum that takes an int called sum, which you can assume
is positive, and an int list, which you can assume contains all positive numbers, and returns ...
3
votes
0
answers
97
views
Printing constructor name in SML
I would like to know whether there would be a way to print the name of the constructor of a datatype from a function in SML. I could find ways to do this in Haskell by deriving the datatype from ...
0
votes
2
answers
86
views
How can I write a function to evaluate custom datatype
datatype mixed_expression =
ME_NUM of int
| ME_PLUS of mixed_expression * mixed_expression
| ME_TIMES of mixed_expression * mixed_expression
| ME_LESSTHAN of mixed_expression * mixed_expression;
...
0
votes
2
answers
135
views
Concatenating strings seperated by spaces in a string list
I am currently writing a code in SML that takes in a string list full of numbers and spaces. The code must combine the numbers up to the space, then create a new list item for the next set of numbers, ...
1
vote
1
answer
133
views
Binding not exhaustive warning in SML/NJ but not in F# for same pattern
The SML/NJ code below results in a binding not exhaustive warning for "val Grove(whatTree) = glen". The F# equivalent code produces no warning. Why?
Standard ML of New Jersey (32-bit) v110....
0
votes
1
answer
587
views
SML Function to make a list from 1 to n
I am new to SML and was a bit confused. I am trying to write a function called makeList of type int -> int list that takes as input a positive integer n and returns the list [1, 2, ..., n]
I want ...
0
votes
1
answer
67
views
Why doe this SML code evaluate to 7 and not 6?
I've been shown this SML code as an example of an inner binding shadowing an outer one.
let val x = 1
in
(let val x=2 in x+1 end) + (let val y = x+2 in y+1 end)
end
After the example, the author ...
1
vote
1
answer
206
views
How do you convert a character to a real in SML?
If I'm trying to do this:
Convert #”N” to a real
What ML expression would do this?
In the same way that:\
str = Char -> string
chr = int -> Char
ord = Char -> int
real = int -> real
Is ...
0
votes
1
answer
133
views
Why does "not" care about "List.exists" input in SML?
I made a function that identifies if a certain object has repetition as following: (PS: test is passing)
(* ListOfPattern -> Pattern -> String List -> List.exists (function) -> bool*)
val ...
-1
votes
1
answer
208
views
how to iterate over a list using one liner msl?
i have a list , and a tuple (start,end,interval) i am trying to iterate over the list and return the elements that are in list from start to end with interval steps . for example:
cutt [1,2,3,4,77,8,7]...