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

How to use if-then-else in a recursive function

I am writing a function that will take a list of list and merge it into sorted pairs of list. For example [[1],[9],[8],[7],[4],[5],[6]] would return [[1,9],[7,8],[4,5],[6]]. This is my first attempt at SML. I keep getting this error: operator and…
R_86
  • 35
  • 9
0
votes
1 answer

How to call two functions in a let..in.. in SML/NJ

I'm trying to call two separate functions within a function. One function generates and presents a random List to a user and the other function uses the random list and sorts it. fun getNumber() = ( print "Please enter the number of integers:…
XXIV
  • 348
  • 1
  • 5
  • 24
0
votes
1 answer

Extracting values from a function via matching

I'm working on an assignment and was given the following function: fun label (lb,ub) = let val s = callcc (fn k =>let fun branch c = if (c < ub) then (pushCP (k,branch,c+1);c) …
oihnkj
  • 1
  • 2
0
votes
1 answer

Input / Output operations - ML

I am learning ML. Can some one please help me out with basic input/output functions in ML?? I just want to read input from console and store it in a variable and use it in my ML program. Please help. If you can point me towards some example for this…
JJunior
  • 2,831
  • 16
  • 56
  • 66
0
votes
1 answer

composition of the functions

I need to write some function NTimesComposition(f:(int * int -> int), n:int) which receives some function f and integer n and after doing composition of f, n times, like this f(x,(f(x,f(x,y)))) <- (here for example n = 3) I began to write it on…
rookie
  • 7,723
  • 15
  • 49
  • 59
0
votes
1 answer

SMLNJ - Function works by itself, but not within another function

I have this function: addBinaryTreeNode((genRandomNumber(100), genRandomNumber(100), genRandomNumber(100)), tree, 1, []) That returns a data type "binaryTree". It will compile when that is by itself, but when I have it in a…
EpicBlargh
  • 1
  • 1
  • 5
0
votes
0 answers

How can I maintain a counter when using map on a list?

This is for a class assignment. I am to implement a function in ML evalxy poly x y where poly is an int list list that represents a polynomial. A term at position n in its inner list and position m in the outer list is the coefficient for x^n * y^m.…
Dr. McKay
  • 2,727
  • 2
  • 15
  • 19
0
votes
1 answer

How to Implement LPT (Longest Processing Time) Scheduling Algorithm function in SML

Suppose that we have a list with the processing time of some tasks,like this [13,8,7,6,4,2,2,1]. we want to divide this list into two list by LPT Scheduling Algorithm.here is the algorithm procedure: with a given Descending sorted list like above,at…
0
votes
1 answer

SML: How to insert elements of a list into another list based on a value?

I have a list and a value, how can I insert elements of the list into a new list until sum of those elements won't exceed that value? The question is how to return the aforementioned new list and initial list without elements of new list? For…
0
votes
1 answer

How to pretty-print tree-like value step by step?

So I've got a datatype: datatype ex = A of int | B of ex * ex; and an example variable: val x = (B (A 1, B (A 2, A 3))); I want to be printing through it like this: "(1, (2, 3))" Any help would be appreciated! Thanks.
rshah
  • 675
  • 2
  • 12
  • 32
0
votes
0 answers

How do I save an Standard ML program?

I am new to SML, but would like to get some experience with a strongly typed language. I've been looking at tutorials and I copied a simple factorial function: fun Factorial n = if n = 0 then 1 else n * Factorial (n-1); However, I am not…
tpm900
  • 271
  • 5
  • 11
0
votes
2 answers

SML check if 2 items are in the same list

How do i check if 2 items are in the same list in sml? I tried changing a member function but i could not make it work. val routeList1 = ["Princes Street", "Haymarket", "Craiglockhart", "Musselburgh", "Stoneybank"] if want to check if both "Princes…
user7422388
0
votes
1 answer

Increase print depth for lists in SML/NJ

I'm using Emacs to write a simple function in sml of about 4 lines and when I try to call the function/evaluate it in the buffer it returns this with 3 dots at the end val it = [1,2,2,2,2,2,2,2,2,2,2,2,...] : int list What's the dots at the end? My…
Square-root
  • 853
  • 1
  • 12
  • 25
0
votes
2 answers

How to keep elements in list through out the program in SML?

Suppose I have to update a list with each call to a function, such that, the previous element of the list are preserved. Here is my attempt: local val all_list = []; in fun insert (x:int) : string = int2string (list_len( ((all_list@[x])) )…
ThunderWiring
  • 738
  • 1
  • 7
  • 29
0
votes
1 answer

Why to replace `in` with `let` in sml?

I have a local block with few helper methods. After that, comes a main function (between the in and end block): datatype color = BLACK | RED; datatype 'a RBTree = Nil | Br of (int * 'a * color) * 'a RBTree * 'a RBTree; datatype Balance = RR…
ThunderWiring
  • 738
  • 1
  • 7
  • 29