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
5
votes
3 answers

New to SML / NJ. Adding numbers from a list of lists

Define a function which computes the sum of all the integers in a given list of lists of integers. No 'if-then-else' or any auxiliary function. I'm new to to functional programming and am having trouble with the correct syntax with SML. To…
user2777383
  • 75
  • 1
  • 3
5
votes
1 answer

How to use infix operator from a SML module?

I have the following to code and I use SML/NJ: signature STACK= sig type 'a Stack val empty :'a Stack val isEmpty : 'a Stack -> bool val cons : 'a*'a Stack -> 'a Stack val head : 'a Stack ->'a val tail : 'a Stack -> 'a…
Dragno
  • 3,027
  • 1
  • 27
  • 41
5
votes
1 answer

unresolved flex record (need to know the names of ALL the fields in this context)

I've been trying to create a function with a tuple-list as an argument but I keep getting the error: "unresolved flex record (need to know the names of ALL the fields in this context)" My code is: fun convert d = ( (map (#1) d) , (map (#2) d)…
giodude
  • 51
  • 1
  • 3
5
votes
5 answers

Using ML in "Real-World" Applications

I really liked learning ML at college. I find functional programming often a refreshingly elegant way to write certain algorithms. I have heard of F# and played around with that a bit. Still, I've written some interesting functions in ML and…
Chet
  • 21,375
  • 10
  • 40
  • 58
5
votes
1 answer

Find if Duplicates Exist SML NJ

I want to write a single function that searches a list and finds if there are any duplicates values in this list. The function should return a boolean. Here is where I'm at, but this is not working... fun myFunc [] = true myFunc(x::xs) =…
MCR
  • 1,633
  • 3
  • 21
  • 36
4
votes
2 answers

Using fold in SML

I'm trying to learn smlnj at the moment and am having trouble with a fold function. What I'm trying to do is write a function, select, that uses the folding pattern and takes in a function and a list. It will take the head of the list into the…
MCR
  • 1,633
  • 3
  • 21
  • 36
4
votes
2 answers

elseif statement in Standard ML?

Im doing a homework problem to make a function sumOdd to computer the sum of the first n odd integers, but i cant seem to find any sort of elseif type statement to do so. What im trying to do is below but of course doesnt work: fun sumOdd n = if n=0…
jfisk
  • 6,125
  • 20
  • 77
  • 113
4
votes
1 answer

SML function on record list

I'm trying to declare a function that takes a list of records inside a tuple as an argument but the syntax is not as intuitive as I would have liked. Here's what I'm trying to do: type Player = {id:int, privateStack:int list}; fun foo(({id,…
Itamar Bitton
  • 777
  • 2
  • 7
  • 25
4
votes
1 answer

How to build SML/NJ executable on Mac

I have an SML/NJ program that I can run as a heap image, and I want to create a standalone executable binary. However, the heap2exec tool in SML/NJ 110.73 always yields errors for me. I created my heap image tigerc.x86-darwin via the…
Jay Lieske
  • 4,788
  • 3
  • 30
  • 41
4
votes
1 answer

How do I run freestanding scripts with SML/NJ?

How do I use SML/NJ to run a script which reads from STDIN and writes to STDOUT say? Is there a way to get rid of the output from the interpreter itself?
August Karlstrom
  • 10,773
  • 7
  • 38
  • 60
4
votes
1 answer

How to convert Real to Int?

Let's say I have 0.0 how do I convert it to 0? I know that I can use Real.fromInt(0) to do the opposite (0 -> 0.0) but what about Real to Int? In the SML documentation I read about a function toInt, but there was no example so I probably use it in…
tonythestark
  • 519
  • 4
  • 15
4
votes
1 answer

How to construct a tuple with only one element in standard ML?

In standard ML (Standard ML of New Jersey), we use following syntax to construct tuple val x = (1, 2); val u = (); However we can not construct tuple with only one element val x = (1); (* normal int *) val y = (1,); (* python syntax, not valid in…
xiang0x48
  • 621
  • 6
  • 20
4
votes
1 answer

Unbound structure Int when compiling useing CM.make

I'm compiling a lexer using CM and ML-Lex. When I try to compile using CM.make "sources.cm", it throws errors. errormsg.sml:7.24-7.39 Error: unbound structure: TextIO in path TextIO.instream errormsg.sml:21.26-21.38 Error: unbound structure: TextIO…
4
votes
1 answer

Keyword "as" in SML/NJ

I recently see people using as in their SML/NJ program. The most helpful reference I found is "as" keyword in OCaml. Though OCaml also belongs to ML programming language family, they are different. For example, in the example program given in the…
Tai
  • 7,684
  • 3
  • 29
  • 49
4
votes
3 answers

SML/NJ not autoloading Basis library on Mac

When I try to use the function List.nth, the sml shell returns this error message: - List.nth([1,2,3],0); [autoloading] unexpected exception (bug?) in SML/NJ: Io [Io: openIn failed on…
cadenzah
  • 928
  • 3
  • 10
  • 23