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
2 answers

Function with different argument types

I read about polymorphism in function and saw this example fun len nil = 0 | len rest = 1 + len (tl rest) All the other examples dealt with nil arg too. I wanted to check the polymorphism concept on other types, like fun func (a : int) : int =…
URL87
  • 10,667
  • 35
  • 107
  • 174
0
votes
1 answer

getting expression doesn't match error

I am trying to implement a node delete function for a Binary Search Tree in SML/nj. However I am getting a constraint error, that I don't understand why... datatype 'a tree = Empty | Node of 'a * 'a tree * 'a tree; datatype 'a stree = STree of ('a *…
omega
  • 40,311
  • 81
  • 251
  • 474
0
votes
1 answer

SML/NJ - the "fun act(f,x) = f(x) ;" signature

Declare on the follow function - fun act(f,x) = f(x); Makes the signature - val act = fn : ('a -> 'b) * 'a -> 'b What does ('a -> 'b) * 'a -> 'b means ?
URL87
  • 10,667
  • 35
  • 107
  • 174
0
votes
1 answer

mutex/lock/semaphore in SML

Does SML have a mutex/lock/semaphore/etc library? I couldn't find one anywhere in the docs. I couldn't even find a multithreading library anywhere. Does it exist?
Peter
  • 1,032
  • 1
  • 11
  • 26
0
votes
1 answer

How to pattern match nested lists?

In sml/nj, I want to create a function that takes a list of non-empty lists, and returns a list of the first elements of each of those non-empty lists. fun get_first [] = [] | get_first x::xs = (hd x)::get_first xs; get_first: ('a list) list -> 'a…
omega
  • 40,311
  • 81
  • 251
  • 474
0
votes
1 answer

SML - Build a new list with the elements of the original list - Error: operator and operand don't agree [literal]

Given a list of numbers , I want to create a new list where the element at index i is the sum of all the i-1 elements before . For example : [1,4,6,9] -> [1,5,11,20] I've written the following code : fun sum nil = 0 | sum [x]=x |…
JAN
  • 21,236
  • 66
  • 181
  • 318
0
votes
1 answer

Check Whether or Not An Input is a Fibonacci Number

fun isfib(a) = findfib(a,1,1) and findfib(b,x,y) = val z = x + y if b <= 1 then true else if z > b then false else if z = b then true else fib(b,y,z) I'm placing an input into the program and recursively trying to find out if…
user1672578
0
votes
1 answer

Handling anonymous functions in SML datatypes

I have the following datatype and 3 examples of tests: datatype 'a test = Test of ('a -> bool) * string; val pos = Test (fn x => x > 0, "pos"); val even = Test (fn x => x mod 2 = 0, "even"); val small = Test (fn x => x < 100, "small"); I'm still…
user595334
0
votes
1 answer

How to pattern match a function?

H, I am trying to do pattern matching, but the input to the function is a curried function, how can you pattern match something like that? Can anyone show me some examples please?
omega
  • 40,311
  • 81
  • 251
  • 474
0
votes
2 answers

foldl operation in SML

I perform the following foldl operation foldl (fn (acc,y) => if acc>y then acc else y+1) 0 [1,3] So, I expect this to produce me an result of 4 but it produces an output of 3. What am I missing ? My trace is something like this: acc: 0 y: 1 acc:…
Sibi
  • 47,472
  • 16
  • 95
  • 163
0
votes
1 answer

SML Case and pattern matching

I have the follwing function that is suppose to return the value of a card. I'm not sure why the case Num => Num is giving the following error: Error: Types of rules don't agree, Earlier rules rank->int this rule rank->int->rank Why would…
Komal Waseem
  • 1,089
  • 3
  • 17
  • 24
0
votes
1 answer

number_in_month exercise (How to return nothing instead of an empty list in SML)

I am doing a programming assignment with SML. One of the functions requires me to return a list of triple tuples of ints ( (int * int * int) list ) use to other lists. The function sorts through dates and months to see if any of them coincide, if…
Sloth
  • 65
  • 1
  • 6
0
votes
3 answers

What is wrong with my function

i have the following function that is supposed to return true if the passed argument is a reasonable date and false otherwise. the problem is that it is returning false even for obviously reasonable dates and i can't figure out what is wrong with…
guthik
  • 404
  • 1
  • 7
  • 15
0
votes
2 answers

SML: List.nth() function does not works inside Let..in..end?

I am back again with a basic question.! ;) I have learned some of the List functions. "List.nth" is one of them. When I use this function in SML command window, It is working fine. But when used inside Let..in..end; block , It is not working. I…
InnovWelt
  • 660
  • 1
  • 8
  • 21
0
votes
4 answers

number_in_month exercise

I am fresh on SML and doing a homework by that. "Write a function number_in_month that takes a list of dates and a month (i.e., an int) and returns how many dates in the list are in the given month." That's what I worked out and cannot see anything…