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

How do you setup StandardML on MacOS Catalina

I have installed by following the instruction here http://smlnj.org/dist/working/110.96/index.html. On that page you have to choose smlnj-amd64-110.96. I clicked on the downloaded package and clicked open which opens the an installer. Once this is…
armand
  • 693
  • 9
  • 29
3
votes
1 answer

Achieving laziness and memoization

Laziness is a corner stone in the book Purely Functional Data Structures, but it is not clearly described how he obtains it, at least to me. I thought I only needed to write: datatype 'a susp = $ of 'a fun force ($x) = x fun plus (x, y) = $case (x,…
Little Helper
  • 1,870
  • 3
  • 12
  • 20
3
votes
2 answers

How to create and use my own structure/signature in SML/NJ?

I'm new to functional programming and I want to create my own structure/signature called Dictionary. So far I have this in file called dictionary-en.sml: (* The signature DICTIONARY defines a type and a programming interface for the dictionary…
Jan
  • 75
  • 6
3
votes
1 answer

isolate in SMLofNJ.Cont

I was reading about continuations in Standard ML (SMLofNJ.Cont). I understood what callcc and throw does, but could not understand isolate. The documentation says Discard all live data from the calling context (except what is reachable from f or…
him
  • 487
  • 3
  • 12
3
votes
1 answer

Lazy suspended tail in sml

I was going through some notes and I realized something is amiss. When emulating lazy computation (without open Lazy;) one can do the following for a stream of ones. datatype 'a susp = Susp of (unit -> 'a) datatype 'a stream' = Cons of 'a * ('a…
phwd
  • 19,975
  • 5
  • 50
  • 78
3
votes
1 answer

Standard ML / CML wrong operator - operand error

I am trying to implement a concurrent list using CML extensions of Standard ML but i am running into errors that are probably to do with my being a newbie in Standard ML. I have implemented the clist as having an input and output channel and I…
spydadome
  • 325
  • 2
  • 9
3
votes
2 answers

Define nested functions in standard ml

I am new in sml. I tried to convert int to int list. For example, assume that there is an input 1234, then output is a list like [1,2,3,4]. And my question is, how can I type nested functions in sml? let in end? There is my code. fun digit (a :…
kw Hyun
  • 67
  • 7
3
votes
2 answers

SML - unzip using map

Given a list of tuples, [(1,2),(3,4),(5,6)] I need to unzip it to look like this [[1,3,5],[2,4,6]] unzip needs to be of type ('a * 'a) list -> 'a list list. So far, I have this as my unzip function but my input is incorrect, and I am not sure…
3
votes
2 answers

SML [circularity] error when doing recursion on lists

I'm trying to built a function that zips the 2 given function, ignoring the longer list's length. fun zipTail L1 L2 = let fun helper buf L1 L2 = buf | helper buf [x::rest1] [y::rest2] = helper ((x,y)::buf) rest1 rest2 in …
3
votes
1 answer

K out on N implementation - SML

I was trying to implement k-out-of-N at SML so "pick(3,[1,2,3,4])" will return [[1,2,3],[1,3,4]...] (all the K-size picks out of N elements) I used List.map which I figured it calls the function and apply it on each element. Really can't figure out…
Zooly92
  • 55
  • 5
3
votes
1 answer

handling exceptions in ML

everyone, I'm trying to understand how exceptions work in ML, but I have strange error, and I can't figure out what is wrong: exception Factorial fun checked_factorial n = if n < 0 then raise Factorial else n; fun factorial_driver () = …
rookie
  • 7,723
  • 15
  • 49
  • 59
3
votes
1 answer

polymorphic lists in ML

I have this snippet of the code in ML: local fun unfolder( [] , n ) = [] | unfolder( l::ls, n ) = (n, l) :: unfolder( ls, n ) in fun flat list = unfolder(list, 1) end; it gives me an error: unexpected exception (bug?) in SML/NJ: EA [EA] …
rookie
  • 7,723
  • 15
  • 49
  • 59
3
votes
1 answer

In SML, is it possible to define an alias for a pattern?

Let's say I have the following datatype datatype mytype = Foo | Bar | Baz and want to write a function like the following fun myfun ((Foo|Bar), (Foo|Bar)) = something | myfun (Baz, _) = somethingelse | ... Is there a way to create an alias for…
Michael Hewson
  • 1,444
  • 13
  • 21
3
votes
3 answers

Print int list in sml

Does there any function exist that directly prints the int list? I have to print int list for debugging purposes. I know that I can achieve this by writing my own functions but I want to know that is there any other method available?
Ankit Shubham
  • 2,989
  • 2
  • 36
  • 61
3
votes
1 answer

SML exponentiation of real with integer

I wrote a function that does exponentiation with a base, b and the exponent e as follows: fun power b e = if e = 0 then 1 else b * power b (e-1); obviously this is works on integers as shown by the output: val power = fn : int -> int ->…
Darrel Holt
  • 870
  • 1
  • 15
  • 39