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

How to import from another file in SML, with a path relative to the importer?

I'm using SML/NJ, and I need to use a set of functions that are in a certain file f1.sml inside another file f2.sml. However, I'm not running f2.sml directly, rather, I'm importing it from somewhere else. If I use the use command in f2.sml with the…
leolovesai
  • 73
  • 3
7
votes
1 answer

nested local declarations in ML of NJ

hello everyone I have this snippet of the code: local helper(f, i, j) = local fun NTimesF(f, n:int) = if n = 1 then fn (x) => f(x) else fn (x) => f(NTimesF(f, n - 1)(x)); …
rookie
  • 7,723
  • 15
  • 49
  • 59
7
votes
0 answers

Does SML/NJ 's Lazy work properly?

I'm using SML/NJ v110.80 and Lazy.I tried the following code in repl Control.lazysml := true; open Lazy; fun f x = f x; let val x = $(f(4)) in 15 end; The last expression should be 15 but it diverges. Did I make a mistake or it just works…
naivehgz
  • 71
  • 3
7
votes
1 answer

What do questions marks mean in Standard ML types?

For instance: vagrant@precise32:/vagrant$ rlwrap sml Standard ML of New Jersey v110.76 [built: Mon May 12 17:11:57 2014] - TextIO.StreamIO.inputLine ; [autoloading] [library $SMLNJ-BASIS/basis.cm is stable] [autoloading done] val it = fn :…
okonomichiyaki
  • 8,355
  • 39
  • 51
7
votes
1 answer

How to write mutually recursive functions within a let binding in SML?

I would like to do something like this: fun f () = let fun a() = b() and fun b() = a() in () end where a and b are sensible mutually recursive functions. However, this gives: Error: syntax error: replacing AND…
user1339898
  • 169
  • 2
  • 5
6
votes
1 answer

How do I time my sml code?

Can anyone tell me how I can time my sml code? I have implemented several different versions of the same algorithm and would like to time them and perhaps even know the memoryusage?
Martin Kristiansen
  • 9,875
  • 10
  • 51
  • 83
6
votes
1 answer

Is it possible to check for pointer equality in SMLNJ (for debugging)?

Suppose we have the following toy binary tree structure: datatype Tree = Leaf | Branch of Tree * Tree fun left(Branch(l,r))= l fun right(Branch(l,r))= r And suppose that we have some large and expensive to compute tree val c: Tree= … val d: Tree=…
kinokijuf
  • 968
  • 1
  • 11
  • 33
6
votes
1 answer

mechanism to get element from the list

is it possible to get element from the list in SML of New Jersey without using function head and tail, something like that: val a = [1,2,3]; a[1]; thanks in advance
rookie
  • 7,723
  • 15
  • 49
  • 59
6
votes
1 answer

SML list equality oddness

I have this bit of code: fun foldr2(f, x::xs) = if xs = [] then x else f(x, foldr2(f, xs)) With the type signature (''a * ''a -> ''a) * ''a list -> ''a Looks pretty straight-forward, it takes a function that works over…
robr
  • 63
  • 2
6
votes
2 answers

Using Successor ML with SML/NJ

I was pleasantly surprised when I saw that SML/NJ recently made some major changes in version 110.79 which is part of a move towards something called Successor ML. This seems to be a cooperative venture between SML/NJ and MLton and bodes well for…
John Coleman
  • 51,337
  • 7
  • 54
  • 119
6
votes
1 answer

Is there a way of constraining a functor's parameter signature so the parameter can supply unspecified equality types to a structure?

If I try to write a parameterized module that calls = on an unspecified type supplied by the parameter, SML/NJ throws a type error. E.g., if I have a signature signature SIG = sig type t end and try to parameterize a module F over a module S with…
Shon
  • 3,989
  • 1
  • 22
  • 35
6
votes
0 answers

Save the current continuation in SMLofNJ

I was reading through this funny page explaing continuations in racket. They present code to save the current continuation of a computation (and use this trick later to implement backtracking). The code looks as follows: (define (currcc) (call/cc…
6
votes
2 answers

Is there a way to get a Curried form of the binary operators in SML/NJ?

For example, instead of - op =; val it = fn : ''a * ''a -> bool I would rather have - op =; val it = fn : ''a -> ''a -> bool for use in val x = getX() val l = getList() val l' = if List.exists ((op =) x) l then l else x::l Obviously I can do this…
Andrew Keeton
  • 22,195
  • 6
  • 45
  • 72
5
votes
1 answer

How to disable SMLNJ warnings?

I'm trying to write command line scripts, but SML's warnings obfuscate the interface. The docs say to use: Compiler.Control.printWarnings := false; But SMLNJ has since renamed these to: Control.printWarnings := false; Which actually produces even…
mcandre
  • 22,868
  • 20
  • 88
  • 147
5
votes
1 answer

SML/NJ while loop

I am really new to SML and I can't figure out how to get answer for the same; It goes something like: 3^4 < 32 but 3^5 > 32 so my answer is 4 (power of 3), similarly if I have numbers 4 and 63 then 4^2<63 but 4^3>63 so my answer is 2(power of 4). I…
Ritesh Ahuja
  • 77
  • 2
  • 2
  • 9
1 2
3
57 58