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

curried function which takes a function and a list of tuples as input

i am trying to define a curried function which takes a function and a list of tuples as input and returns a Boolean value for example values(fn (x,y:int)=>(x-y) [(5,0)]; val it = true:bool but my problem is i don't know how to pass a dynamic…
Asav Patel
  • 1,113
  • 1
  • 7
  • 25
0
votes
1 answer

Returning the position in a list (ML)

Define a function which, given a list L, an object x, and a positive integer k, returns the position of the k-th occurrence of x in L if x appears at least k times in L otherwise 0. For example, if L is [#"a", #"b", #"c", #"b"], x is #"b",…
0
votes
3 answers

Finding largest value using tail recursion

I'm trying to find the largest value of a list using tail recursion. I can't use any auxiliary functions, though...so it must be done using recursion. I've written a function to find the max, starting from the head, but don't know how to implement…
0
votes
1 answer

Check whether number is Fibonacci or not in Standard ML

I am trying to write a code which checks if number is Fibonacci or not in ML. I am a beginner. Help me find out what is the problem with my code. fun isfib(n :int): bool= let val a1=1; val a2=1; val temp=0; in while a2
Asav Patel
  • 1,113
  • 1
  • 7
  • 25
0
votes
2 answers

New to SML / NJ. Making a custom insert function

Define a function that, given a list L, an object x, and a positive integer k, returns a copy of L with x inserted at the k-th position. For example, if L is [a1, a2, a3] and k=2, then [a1, x, a2, a3] is returned. If the length of L is less…
user2777383
  • 75
  • 1
  • 3
0
votes
1 answer

SML - Base case, wrong return value for declared datatype

I'm having trouble with the base case of a function that I'm writing. I have a datatype that I've declared. In the base case I need to replace the nil with something. How do I tell it that the function won't return anything? datatype 'a newThing…
Andrew_CS
  • 2,542
  • 1
  • 18
  • 38
0
votes
2 answers

SML - Incrementing a value in a tuple during foldl that needs to be returned

I'm having a problem while trying to increment my value of x inside the inner foldl call. I make x equal to shiftValue that's passed in and attempt to increment it whenever I find a #" " or #"*" in the inner foldl call, but the value of x that gets…
Andrew_CS
  • 2,542
  • 1
  • 18
  • 38
0
votes
1 answer

ML compile error in a function

After hours of fixing the following code I got stuck in the following compile error message and no matter what I try, I cannot fix it. Error: syntax error: deleting END RPAREN FUN the code is: fun we (array1 , k, n, fif1) = if Queue.isEmpty fif1…
brera
  • 1
0
votes
1 answer

SML: Scan a relation list to get all the transitive associations

I have an environment list which keeps associations between variables and values, such as env = [("x", 1), ("y", 2), ("z", 3), ...]. I also have another substitution list (which is returned by a pattern matching control function) that keeps…
Dree
  • 702
  • 9
  • 29
0
votes
1 answer

Why can't I access my structure's internal ORD_SET structure?

This exercise I made up is intended to help me understand signatures, structures, and functors in Standard ML. I can't seem to get it to work. Just for reference, I'm using Standard ML of New Jersey v110.75 [built: Sun Jan 20 21:55:21 2013] I have…
JeremyKun
  • 2,987
  • 2
  • 24
  • 44
0
votes
1 answer

Issue matching Type of function to one defined in signature

I have a structure to define lazily evaluated sequences which are defined as datatype 'a seq = Cons of 'a option * (unit -> 'a seq) and I have a function map() that maps a function of type ('a->'b) to the values in the sequence. val map : ('a ->…
jasimp
  • 73
  • 5
0
votes
1 answer

How can I convert my data type?

I define a data type for a multi list: datatype intnest= INT of int | LIST of intnest list; now I'm trying to write function which can convert this type to main type. for example: [INT 1, INT 2, LIST[INT 6, INT 8]] => [1,2,…
sarah
  • 19
  • 2
  • 7
0
votes
1 answer

How can I define a heteregeneous list datatype?

I am just starting to learn SML and having issues. I want to define a datatype, for a list that is not homogeneous. Take for example val a = [1,[2,4,3],5,[2,6]] I have made this datatype datatype 'a MulList = List of 'a multiList list …
sarah
  • 19
  • 2
  • 7
0
votes
1 answer

inserting EQUALOP error in SML

I am trying to swap elements in a list in ML. My swap function returns the error inserting EQUALOP. fun swap(n:int, i:int, deck:card list) = local val card1_removed = nth(deck,i) val…
David Farthing
  • 237
  • 2
  • 13
0
votes
2 answers

SML/NJ - about ":=" operator

I did some checks on := operator and I want to make sure that I got it well . let - val r1 = ref 1 ; (* !r1 = 1 *) val r2 = ref 2 ; (* !r2 = 2 *) val r3 = ref 3 ; (* !r3 = 3 *) r1 := !r2 ; (* !r1 = 2 *) r2 := !r3 ; (* !r2 = 3 *) !r1 ; (*…
URL87
  • 10,667
  • 35
  • 107
  • 174