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
4
votes
1 answer

Convert a Haskell function to SML

I'm trying to convert a Haskell function, which displays a boolean formula, to a SML function. The function: data Formula = Atom String | Neg Formula | Conj Formula Formula | Disj Formula Formula precedence :: Formula ->…
TheAptKid
  • 1,559
  • 3
  • 25
  • 47
4
votes
1 answer

How to flatten a list non-recursively in sml/nj?

fun flat [] = [] | flat (l::ls) = l @ flat ls; This will flatten a list. Is there a way to non recursively do the same operation? Perhaps with HOFs?
Dickson
  • 43
  • 1
  • 3
4
votes
1 answer

How do I change a single char to an int in sml/nj

I am just trying to change the char to int and return the int.
Graeme
  • 41
  • 2
4
votes
5 answers

BigInt for Standard ML/NJ

Is there a Java BigInt equivalent for Standard ML? The normal int type throws an exception when it overflows.
rezusr
  • 63
  • 1
  • 5
4
votes
3 answers

Running Standard ML on Windows

I have been looking for some good documentation on how to get Standard ML running on windows. Does anyone have a good guide on this? I have tried compiling sml/nj in cygwin, using this guide: http://www.smlnj.org/install/index.html $…
user833970
  • 2,729
  • 3
  • 26
  • 41
3
votes
1 answer

Foldl return a Tuple in SML?

The problem I'm working on needs to take in a list of integers and return the average of those numbers. It needs to fit a specific format that looks like this... fun average (n::ns) = let val (a,b) = fold? (?) ? ? in real(a) / real(b) end; I'm…
MCR
  • 1,633
  • 3
  • 21
  • 36
3
votes
1 answer

SML - collecting words in a trie using continuations

I have a datatype trie = Node of char * (trie ref) list | Empty And I want to collect all the words in the trie, using these two mutually recursive functions: words_in_trie: trie -> (char list list -> 'a) -> 'a all_words: trie ref list -> (char…
Lanaru
  • 9,421
  • 7
  • 38
  • 64
3
votes
1 answer

SMLNJ want to remove "val it = () : unit" from every print statement execution

I am writing sml programs which run on SML/NJ and MLton (not interactive). When I use print statements in the the sml file, SML/NJ always adds val it = () : unit to the output, which clutters up the output. MLton does not do this. Is there a…
DougT
  • 231
  • 1
  • 10
3
votes
2 answers

find whether a string is substring of other string in SML NJ

In SML NJ, I want to find whether a string is substring of another string and find its index. Can any one help me with this?
Harish
  • 7,589
  • 10
  • 36
  • 47
3
votes
2 answers

How to coerce a type in SML (like casting)

I'm creating a structure of Rationals (int * int) and one of my functions is: fun diff ((n, d), (n', d')) = let val (top, bot) = sum ((n, d), (~n', d')) in (top / gcd(top, bot), bot / gcd(top, bot)) end gcd gives me the greatest…
Kai
  • 3,997
  • 4
  • 30
  • 36
3
votes
2 answers

How can I customize the SML/NJ interactive loop?

I'm new to Standard ML and I'm trying to get my head around the SML/NJ runtime environment. I want to adapt it to my needs. Specifically, I want to: Use IntInf by default Prevent it from truncating strings and IntInf to 70 characters. Here's what…
Barry Brown
  • 20,233
  • 15
  • 69
  • 105
3
votes
1 answer

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 defining a signature as follows signature A = sig …
elTomato
  • 333
  • 3
  • 11
3
votes
0 answers

Printing constructor name in SML

I would like to know whether there would be a way to print the name of the constructor of a datatype from a function in SML. I could find ways to do this in Haskell by deriving the datatype from libraries like show but not in SML. I need this…
blueconch
  • 31
  • 2
3
votes
1 answer

SML: Exception while reading a line of integers

fun parse file = let (* A function to read an integer from specified input. *) fun readInt input = Option.valOf (TextIO.scanStream (Int.scan StringCvt.DEC) input) in (Array.update(acc,readInt inStream, f+1);…
tonythestark
  • 519
  • 4
  • 15
3
votes
2 answers

Return a list of even numbers from a list of integer pairs in sml

I have the following question "Given a list of integer pairs, write a function to return a list of even numbers in that list in sml". this is what I've achieved so far val x = [(6, 2), (3, 4), (5, 6), (7, 8), (9, 10)]; fun isEven(num : int) = …
John Smith
  • 229
  • 3
  • 11