Questions tagged [sml]

Standard ML is a high-level functional language with type inference.

Filter by
Sorted by
Tagged with
0 votes
1 answer
42 views

SML Looping through 2 Random variables and ordering them?

I am trying to use SML to do the following: print a tuple of 2 integers, the first being a number 1-50, and the second being 1 (this is what I have so far): val nextInt = Random.randRange (1,50); ...
Em S's user avatar
  • 1
1 vote
1 answer
24 views

How do I fix my standard ml code when I have an unbound value 'a'?

This a function seconds that takes a list of pairs and returns a list of the first objects in the pairs. fun seconds (pairs : (a * b) list) : b list = let fun first (pair : a * b) : a = fst pair ...
Moises4's user avatar
  • 11
0 votes
1 answer
40 views

How to install and run SML/ NJ in VScode

For the veteran programmers out there, how can I install and run the SML language in my VScode? Both syntax highlighting and interpretation. Thank you for your time
Azury's user avatar
  • 80
0 votes
1 answer
36 views

UTF-8, Unicode in SML/NJ

I am playing with SML/NJ (version 110.99.4) on Windows 10. I have a structure containing a text file in UTF-8 encoding: ... let val s:string = "søk" in print s end; .....
RandomB's user avatar
  • 3,396
0 votes
1 answer
99 views

What is the difference between ('a,'b) and ('a*'b)?

In Haskell we have a tuple type like (a, b, ...). I am trying to read some SML code and I already know that a value (a, b) type is a * b. But then I saw this: type ('a,'b) reader = 'b -> ('a * 'b) ...
RandomB's user avatar
  • 3,396
0 votes
1 answer
29 views

sml standard pop function vs user defiend. And return values

i have a few questions about pop() standard function and myPop() function that i have defined and related return type. 1. fun myPop(L)= if null L then raise EmptyList else (hd L,tl L) val myPop = fn:'...
and's user avatar
  • 31
2 votes
2 answers
54 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 ...
Vikas Mishra's user avatar
0 votes
2 answers
43 views

Recursive function that deals with "ref" in SML

This is my first recursive function; I'm new to the programming world. So, the code does really confuse me. I discovered that SML doesn't allow variable updating. So I learned to use ref, and that ...
hayam Mohammed's user avatar
0 votes
4 answers
66 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 = ...
Ishan's user avatar
  • 11
1 vote
1 answer
55 views

How do I append a record triple to a list in sml

fun same_string(s1 : string, s2 : string) = s1 = s2 fun all_except_option(str, []) = NONE | all_except_option(str, x::xs) = case same_string(x, str) of true => SOME xs ...
user13017933's user avatar
0 votes
0 answers
45 views

What's relation between source code of standard ml in github and compiler.tgz?

In http://www.smlnj.org/dist/working/110.99.3/index.html I can find the compiler.tgz:http://smlnj.cs.uchicago.edu/dist/working/110.99.3/compiler.tgz it seems it's the source code of smlnj,I can find ...
wang kai's user avatar
  • 1,725
0 votes
1 answer
35 views

SML: What is the difference of input and inputAll

I am writing a program in SMLNJ which should open a txt file and then create a list with each character from this file. So I did this: val charlist = explode(TextIO.input(TextIO.openIn "myfile....
lil_papa's user avatar
1 vote
1 answer
53 views

Function to Return Datatypes in SML

For homework, I need to design an SML function that returns the type of a custom datatype which matches some input data. Here's the general idea: we are given a custom datatype typ-- datatype typ = ...
Scentless Apprentice's user avatar
1 vote
1 answer
45 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) ...
lil_papa's user avatar
0 votes
0 answers
61 views

How can I convert a regular sequence to a biseq in SML?

I have the following data type of a 2 way sequence: datatype direction = Back | Forward; datatype 'a biseq = bNil | bCons of 'a * (direction -> 'a biseq); and I am trying ...
Maya's user avatar
  • 1
1 vote
1 answer
45 views

Why does the right-hand-side of clause not agree with function result type?

Starting with this data type defined in SML -- datatype exp = Constant of int | Negate of exp | Add of exp * exp | Multiply of exp * exp I've written this function which is ...
Scentless Apprentice's user avatar
1 vote
0 answers
63 views

Why is the result of the following functor not opaque?

Consider the following SML program: signature BinaryOp = sig type domain val operation: (domain * domain) -> domain end; signature INTEGER = sig val value: int end; functor ModularInt(...
Marco's user avatar
  • 499
0 votes
1 answer
37 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 ...
Hank Lenzi's user avatar
0 votes
1 answer
36 views

Type clash expression of type int * int cannot have type int * int * int on SML

I'm trying to make a code on Moscow ML/SML about magic squares. Whenever I try to run the code, I always get this error on line 15: ! Type clash: expression of type ! int * int ! cannot have type ! ...
spacecowboy's user avatar
-5 votes
1 answer
54 views

Please, help me. I'm a beginner and I don't really understand [closed]

Write a function min_max : int list -> int * int that takes a non-empty list of numbers, and returns a pair (min, max) of the minimum and maximum of the numbers in the list. Here is what I've ...
Maslo Kar's user avatar
0 votes
2 answers
43 views

In Basic SML I cant seem to fix this mismatch type error

structure Random = (* Define a module named Random *) struct val rand = Random.rand (* Expose the rand function from the Random library *) end; fun generateRandomArray() = let val ...
user avatar
2 votes
1 answer
38 views

In this SML code I'm trying to open a file selected by the user but I keep getting a tycon mismatch error

I am working on a Standard ML (SML) program that reads a file given by the user and prints the first line of the file. I have written the following code: fun readAndPrintLine instream = case ...
Subtle_Overtones's user avatar
0 votes
0 answers
48 views

Install SML for Computational Category Theory

I am following Computational Category Theory and learning Standard ML. However SML has changed since the book was published, and I am having a little trouble executing the examples/exercises (for ...
Julián Villaquirá's user avatar
1 vote
1 answer
48 views

How to check if x value exists in a list

This is my code: fun exist [] x = false | exist l::ls x = x=l orelse exist ls x And I tried to compile, but I got these errors; Error: infix operator "::" used without "op" in ...
hhhamster's user avatar
0 votes
2 answers
75 views

How to cast value in SML? Trying to take return type of S-Expression parser and convert to data structure

I am using the S-Expression library included in SML/NJ. In my use case, my file containing the SExpressions will always be of type String List List List. The SExpParser.parse successfully parses my ...
Vlad Zhdanov's user avatar
0 votes
2 answers
42 views

print/return cons version of a list in SML

I want smlnj to return a list in its cons form when I input a list in the regular list notation. Is there a way to get smlnj to do this for me? Here is an example: input: [1,2,3] output: 1::2::3::[] ...
AKapoor30's user avatar
0 votes
1 answer
71 views

Are tuples comparable in SML?

Suppose we needed to compare values inside tuples (to give context, let's say a tuple of 3 values represents a data dd/mm/yy) & we want to check which if date1< date2. Is it possible to compare ...
Diana Farhat's user avatar
-2 votes
1 answer
105 views

SML if and else if // boolean fuction

I am solving this exercise that takes 2 tupples in SML (intintint) (date month and year) "Write a function is_older that takes two dates and evaluates to true if the first argument is a date that ...
haffpuff's user avatar
0 votes
1 answer
68 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 ...
Danial's user avatar
  • 402
2 votes
2 answers
170 views

Evaluation order of let-in expressions with tuples

My old notes on ML say that let (𝑣₁, … , 𝑣ₙ) = (𝑡₁, … , 𝑡ₙ) in 𝑡′ is a syntactic sugar for (λ 𝑣ₙ. … (λ 𝑣₁. 𝑡′)𝑡₁ … )𝑡ₙ and that let (𝑣₁, 𝑣₂) = 𝑡 𝑡′ in 𝑡″ is equivalent to let 𝑣 = 𝑡 ...
user avatar
2 votes
2 answers
38 views

SML recursive type error when converting numbers to nat form

I am practicing SML and getting the following recursive type error. Is ML complaining about type recursive and needs some type hints? I am confused. datatype 'a nat = Zero | Succ of 'a ; fun ...
Node.JS's user avatar
  • 1,099
0 votes
1 answer
65 views

RunCall structure of Poly/ML

I'm reading Isabelle's source code while I'm not experienced with programming in general. I found the use of RunCall structure of the Poly/ML basis library (e.g. in src/Pure/Concurrent/...
opus26's user avatar
  • 38
0 votes
1 answer
84 views

Datatype declaration by datatype in Standard ML

I'm trying to read the source of Isabelle even though I'm a beginner of Standard ML. I arrive at the structure Unsynchronized in src/Pure/Concurrent/unsynchronized.ML, which seems for the multi-thread ...
opus26's user avatar
  • 38
0 votes
2 answers
33 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 ...
user avatar
0 votes
1 answer
65 views

Why does SML not recognize certain types unless I put it in a variable?

I have the following type: datatype pattern = Wildcard | Variable of string | UnitP | ConstP of int | TupleP of pattern list | ConstructorP of string * ...
serp002's user avatar
  • 117
0 votes
2 answers
84 views

Declare multiple variable bindings in one line in SML

Is it possible to declare multiple variable bindings in one line in SML? For example, I have the following: let val m1 = [1] val m2 = [2] val m3 = [3] in {...} end I would like to ...
Ashwin's user avatar
  • 51
1 vote
1 answer
41 views

How to write a function of type ('a * 'b -> 'b) -> 'a list -> 'b -> 'b

I'm new to Standard ML. I know that fun foldr f [] a = a | foldr f (x::xs) a = f x (foldr f xs a) type = ('a -> 'b -> 'b) -> 'a list -> 'b -> 'b How can I modify to change the type ...
lu123's user avatar
  • 11
0 votes
1 answer
25 views

Can't access the value of int in a double list sml

I cant access the value of int*int inside a double list fun fnd(xs:(int*int)list list)= if null xs then 0 else #2 xs example i input fnd [[(1,2)]]; i want to print the second value which ...
SoRA's user avatar
  • 5
0 votes
2 answers
79 views

sml match non exhaustive warning

i want to make a function that return 0 if the list is empty otherwise 1 and the binding shoul be ( val len = fn : (int * int * int) list list list list -> int ) fun len[[[(x:(int*int*int)list)]]]=...
SoRA's user avatar
  • 5
2 votes
1 answer
108 views

How can I have String.tokens use more than one delimiter?

Because String.tokens is a curried function, I know I can change String.tokens (fn c =\> c = #" ") "hello world"; to a string that would contain all the delimiters, but I am ...
johnlewenskal's user avatar
1 vote
1 answer
62 views

Having trouble creating exhaustive pattern matching SML

I can't seem to figure out how to fully pattern-match this function. I want to check if a list is sorted using a function as an argument to say which order (inc or dec, < or >). I think my base ...
johnlewenskal's user avatar
1 vote
1 answer
61 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 ...
foxy's user avatar
  • 60
0 votes
1 answer
70 views

Compare two values of two "lists" against each other and count instances where values match

To start, let me share that I'm a complete novice at formal programming and have decided to start learning after many years of working in IT from the administrative side. So I am starting from ...
Mr. TAO's user avatar
3 votes
1 answer
143 views

Defined functions in structures in SML results in "value type in structure does not match signature spec"

It has been quite a while since I've been programming in SML and now I'm stuck on what looks to me a very simple issue. I'm defining a datatype like datatype 'a Something = Something of 'a then I'm ...
elTomato's user avatar
  • 333
2 votes
2 answers
109 views

Why is there no error when defining a function using these overloaded operators?

I am reading Programming with Standard ML by Colin Myers, Chris Clack, and Ellen Poon. In § 2.4.1 Restricted polymorphic functions: Unlike the operators = and <>, the other comparison operators ...
Flux's user avatar
  • 10.1k
0 votes
1 answer
31 views

SML counting within a pair of lists

I am trying to write a function in SML that takes in a pair of lists. The first list in the pair is a list of integers and the second list is a list of booleans. Ex: (([3, 5, 9], [true, false, false]))...
jack1598's user avatar
0 votes
1 answer
56 views

List of lists in SML/NJ given a list and wanting to satisfy a condition. I get problem: An expression of type "'a" cannot have type "'a list"

We have a list such as [1,2,7,5,3,2,8,9] and we want to create a list that includes lists of groups of those numbers so that each group does not have decreasing order of its numbers. For example for ...
Dora Boutsini's user avatar
1 vote
1 answer
470 views

Reversing a list in SML

fun reverse ( [] ) = ( [] ) | reverse (x::xs) = reverse (xs) :: [x] why my this function of reversing a list is not working
Aaryuman Sawai's user avatar
4 votes
1 answer
124 views

Why does OCaml succeed in matching 'a list with int list, while Standard ML fails to do so?

In OCaml, let f (x : 'a) : 'a list = x :: [0] has signature val f : int -> int list. When I try to define a similar function in Standard ML, fun f (x : 'a) : 'a list = x :: [0], there is an error. ...
Flux's user avatar
  • 10.1k
0 votes
1 answer
48 views

SML returns the same tuples

I'm currently learning Standard ML, just for fun; What I'm trying to do is generate a list of 3-tuples of random ints between 1 and 100. My code: fun reload() = use "filtertest.sml"; fun ...
OrangeCalx01's user avatar

1
2 3 4 5
42