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

SML - Iterate through String

I'm trying to find if sentences read from a file has some pattern. So far, I've written the code that reads all the sentences from file line by line, and puts those sentences to an array. val infile = "c:/input.txt" ; fun readlist (infile : string)…
Lebanner
  • 77
  • 1
  • 1
  • 9
3
votes
1 answer

Recursing Binary Decision Diagrams in SML

In one of my classes at university, we are learning functional programming through SML/NJ. I have been given an assignment which requires us to perform a number of operations on Binary Decision Diagrams. (conjunction, disjunction, not, etc.) Based…
Andrew Brooke
  • 12,073
  • 8
  • 39
  • 55
3
votes
3 answers

SML Error:Types of if branches do not agree

I am trying to find if an element is a part of a set. Here is my function: fun elementOf(x:int, (nil:int list, nil:bool list)) = nil | elementOf(x, (y::ys, z::zs)) = if x = y then z else elementOf(x, (ys, zs)); So if I were to call elementOf(2,…
TGuedes
  • 69
  • 1
  • 6
3
votes
4 answers

SML : Count the number of '\n' in a String

I'm quite new in Standard ML and I have a question that will probably be obvious to someone who knows how to code in this language. I've got an original function as follow : fun getBlocked w = case BlockingMgr.listBlockedSuccessors w of nil =>…
Valentin Montmirail
  • 2,594
  • 1
  • 25
  • 53
3
votes
1 answer

How does the compiler determine types in sml

I've been given the following code and I've been asked to determine the type. exception Break; fn f => fn a => fn b => (f(raise Break) handle Break => if (f a) then a else raise Break) handle Break => if not(f a) then a else…
James
  • 1,259
  • 1
  • 10
  • 21
3
votes
1 answer

SML signature with multiple structures

Say I have an SML signature ALPHA. But I also have multiple structures/functors alpha1, alpha2, etc that I wish to use with ALPHA. My question is this, if I were to have a struct that performs unit testing outside these modules, how would I solely…
Fadhil Abubaker
  • 137
  • 1
  • 9
3
votes
2 answers

SML arithmetic function's type is inferred to int

When defining a simple function that takes the square of a value, SML NJ infers the signature for this function to integer types. When declaring the signature for float types, SML can work with floating point values here. - fun sqr x = x * x; val…
wirrbel
  • 3,173
  • 3
  • 26
  • 49
3
votes
1 answer

Handling Keyboard Interrupts

I've got a minimal TCP server running in the SML/NJREPL, and I'm wondering how to gracefully close the listener socket on a keyboard interrupt. A stripped-down version of the server is fun sendHello sock = let val res = "HTTP/1.1 200…
Inaimathi
  • 13,853
  • 9
  • 49
  • 93
3
votes
1 answer

Large Int Set in sml

I'm having the following problem in sml: i want to create a set using the IntListSet signature but instead of int I want to use large int. Is there any way to fix this? Thank you, awaiting for your answer .
ysig
  • 447
  • 4
  • 18
3
votes
4 answers

Zip and unzip lists in Standard ML

How to create a function to zip and unzip two lists as tupled lists in Standard ML? Example: unzip [[1,4],[2,5],[3,6]] -> [1,2,3] [4,5,6] zip [1,2,3] [0,2,4] -> [[1,0],[2,2],[3,4]]
jetpackman
  • 53
  • 1
  • 7
3
votes
2 answers

Format exception SML

I'm using Linux Mint 17 and I recently installed smlnj (Standard ML of New Jersey) and sml-mode for Emacs with apt-get. When I try to increase the print depth with the command Control.Print.PrintDepth := 100; I get the following error: -…
Liz
  • 363
  • 3
  • 12
3
votes
3 answers

foldl vs foldr: which should I prefer?

I remember that when I showed some code that I wrote to my professor he remarked, offhand, that It rarely matters, but it's worth noting that fold* is a little bit more efficient than fold*' in SML/NJ, so you should prefer it over fold* when…
Patrick Collins
  • 10,306
  • 5
  • 30
  • 69
3
votes
2 answers

SML/NJ string pattern matching

Is there something like list pattern matching in SML/NJ, but for strings? What I want to do eventually is to remove the first character of a string, if it's a specific one, and a solution of this kind came first to mind, so I would appreciate it if…
Noob Doob
  • 1,757
  • 3
  • 19
  • 27
3
votes
1 answer

Standard ML printing control characters

So I've stumbled on what seems to be a weird little problem. I want to print control characters, which should print that weird little box suggesting that I'm trying to print a non-printable character. When I try: print "\^C"; it works fine. However…
robins35
  • 653
  • 12
  • 37
3
votes
2 answers

Writing Bubble Sort using Foldl or Foldr in SML

Is there a way to implement bubble sort using the Foldl or Foldr methods available in SML? Any guidance would be helpful.