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

Get list of values less than input - ML

I am trying to create code that takes an integer 'a' and a list and returns a list of every value in the list that is less than a. I have created code that will figure out if the first number in the list is less than 'a' but I can't quite figure out…
M. Pollino
  • 45
  • 6
0
votes
1 answer

What does '#' mean in SML?

I have a function, that creates a new tree, based on an old one, and the min/max values of each node from the old one. using the datatypes: datatype 'a Tree = LEAF of 'a | NODE of ('a Tree) * ('a Tree) and datatype 'a myTree = myLEAF of 'a |…
Oppa
  • 154
  • 8
0
votes
1 answer

Defining Tree's and Search Function

I am trying to define my tree and create a search function, but I think I am getting lost in the syntax of SML. Here is my tree datatype either = ImAString of string | ImAnInt of int; datatype eitherTree = Empty | eLEAF of either…
0
votes
3 answers

How to find the min and max values of a tree in SML

I have the two datatypes: datatype 'a Tree = LEAF of 'a | NODE of ('a Tree) * ('a Tree) and datatype 'a myTree = myLEAF of 'a | myNODE of 'a * 'a * 'a myTree * 'a myTree With these two, I need to be able to find the min and max values of a tree.…
Oppa
  • 154
  • 8
0
votes
1 answer

SMLNJ powerset function

I am trying to print the size of a list created from below power set function fun add x ys = x :: ys; fun powerset ([]) = [[]] | powerset (x::xr) = powerset xr @ map (add x) (powerset xr) ; val it = [[],[3],[2],[2,3],[1],[1,3],[1,2],[1,2,3]]…
bapuy
  • 17
  • 5
0
votes
1 answer

Finding matching numbers in lists SML

I am trying to write a function in SML where there are two lists being passed into a function, and if both lists contain the same number (or multiple of the same number) those numbers are added to a new function. fun shared([], []) = [] let …
0
votes
2 answers

Syntax for a function with (’a * ’b) list → (’b * ’a) list

I am trying to write a function to swap a pair of tuples inside of a list like this: - pairSwap [(1, 2), (3, 4), (5, 6); [(2,1),(4,3),(6,5)] I am having a hard time figuring out what I am doing wrong with my syntax while declaring the function.…
Jordan
  • 75
  • 1
  • 5
0
votes
1 answer

SML: Interpret function from its type

I am new to SML (meta-language). Can anyone tell me how to derive the function from the type given as below: (’a -> ’b) -> (’b list -> ’c) -> ’a -> ’c list I am having a hard time in understanding the curried functions in SML.
Aniruddh Khera
  • 111
  • 1
  • 13
0
votes
2 answers

How to declare an argument as a function in SML?

my question goes like this: how can I define a function , that receives a function without using type constraints or in other words, without having to type fun f1(f2:type->type) ? I'm trying to think of a way that uses the argument f2 as a function…
Basilm
  • 23
  • 6
0
votes
1 answer

Ideas for counting specific characters in a string

I'm very new to SML and I'm trying to write a function that determines whether a string is balanced or not. A balanced string is: 1. a string where the number of "(" occurrences is equal to the number of ")". 2. in every prefix ")" does not occur…
Basilm
  • 23
  • 6
0
votes
1 answer

Write ML function

I'm new to ML so I'm doing my best to understand. Write an ML function called alternate : 'a list -> 'a list, that takes two lists, having the same length, as input and produces an output list whose elements are alternately taken from the first and…
0
votes
3 answers

ML how to check type of list and give error massage?

I want to write a sample function that takes a list of any type and returns the head element only if the list is a list of reals. Otherwise, the function should give the error message . . . E r r o r : operator and operand don ’ t . . . datatype…
joshua
  • 947
  • 2
  • 8
  • 14
0
votes
2 answers

SML/NJ searching in list of tuples of list

I am very new to SML/NJ and I am kind of lost. I have been trying to implement a function that is going to search through the list of tuples that have some lists in it, for example: val x = [(5, 2, [9 , 8, 7]), (3, 4, [6, 5, 0]), (11, 12, [8, 3,…
0
votes
1 answer

SML - Error: types of if branches do not agree

I am trying to code an SML function that returns an array of results in listViolations(L1, L2). I specifically want to cross reference each element with eachother O(n^2), and check to see if the selection conflicts with one another. To visualize:…
EDU Codes
  • 11
  • 4
0
votes
1 answer

Error in SML code

Hi i am getting compilation errors in the following SML code, can someone help? Error: operator and operand don't agree [UBOUND match] operator domain: 'Z list operand: ''list in expression: null mylist stdIn:4.15-4.24 Error:…
Bhargav
  • 697
  • 3
  • 11
  • 29