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

Tail recursion in SML does not present any output

Following my previous post here , I tried to do what was suggested and convert the code into a Tail-recursion method with let . The original code - which does not work (due to using val inside if condition) : fun func() = val decimal = 0 (* the…
JAN
  • 21,236
  • 66
  • 181
  • 318
0
votes
4 answers

how to run sml/nj program under emacs

after one day struggle I finally configure Emacs for SML/NJ. I am new to both emacs and SML, now I am having problem to how to run sml program under emacs. when I command, M-x sml-mode it looks OK, no error report. and after open(or create file…
user1869952
0
votes
2 answers

Recognition of data type in SML

This is confusing but working code. I just want some help in understanding why k::ks is taken as a'list list list and not a'list list. I want to take a list and a list of lists and check whether the first list is necessary. By necessary I mean,…
user1709828
0
votes
1 answer

Where am I going wrong with this code?

I am trying to calculate the sum of the squares of the first n numbers. Here is the code: fun sumSq 0 = 0 | sumSq x = x + sumSq(x * x-1); I am getting an uncaught exception Overflow[overflow] error.
Graeme
  • 41
  • 2
0
votes
1 answer

Print error in SML because of types mismatch

I' trying to print a types value in SML and with no success. Please take a look at the code below and let me know what do I need to do in order to fix this. Thanks. (* Language Definition *) datatype = Id of string; (* Expression Definition…
Alexander Tilkin
  • 149
  • 1
  • 2
  • 13
0
votes
1 answer

Assigning values to a list of variables

I want to input two lists of equal length and assign the values of one list to variables of another. I want it to realize first list automatically as list of variables and second as values. e.g. I want to assign [1,2,3,4,5,6] values to the elements…
700resu
  • 259
  • 6
  • 16
0
votes
1 answer

Count number of occurances of an element in a list

I have the following function: getcountof(x,l::ls) = if x=l then (1 + getcountof(x,ls)) else getcountof(x,ls) |getcountof(x,[]) = 0; Can someone tell me whats wrong in it? I get the error: stdIn:1.2-1.17 Error: syntax error: deleting ELSE…
Rpant
  • 974
  • 2
  • 14
  • 37
0
votes
2 answers

How do I make a function that writes data into a file give boolean output?

I have to write a code that takes integer list and writes them to a file. At the same time it returns true if the element is written, else false if it is not written. I wrote something like fun writetofile([],sfile)= false |writetofile((l:int)::ls,…
700resu
  • 259
  • 6
  • 16
0
votes
1 answer

withtype fails with mlton and succeeds with smlnj

I am writing an application where I want to define many types in the withtype clause of a datatype declaration. The following code snippet demonstrates it: datatype ta = A withtype tb = int and tc = tb mlton fails to compile this code,…
Romildo
  • 545
  • 9
  • 20
0
votes
1 answer

writing integers to a file in sml

Is there a output in textIO signature to write integers to a file? output only writes vectors, outputsstring writes substrings and output1 writes only characters. My problem with not using vectors is I have to write each integer into a line in the…
700resu
  • 259
  • 6
  • 16
0
votes
1 answer

Is there a inbuilt function to check if a number is integer in SML

Is there an inbuilt is integer function in sml? I mean something like: I have to read a number from file and display it as output if it integer and raise exception if the number is not integer. for example I have to check if the output of…
700resu
  • 259
  • 6
  • 16
0
votes
2 answers

How to exit a function without returning a value

Suppose I have a function that returns a certain value when it satisfies a given condition and does not return any value when the condition is not satisfied. e.g. fun foo(n)= if n< 100000 then n else (something like exit function. We have it in…
700resu
  • 259
  • 6
  • 16
0
votes
1 answer

Understanding Text IO

My function is trying to read a textfile line by line and carry out a certain predefined function on each line called somefn and append the value of somefn to the function. The somefn is already defined above this and works fine. fun…
700resu
  • 259
  • 6
  • 16
0
votes
1 answer

Raising IO Exceptions in SML

Exception IO has structure: Exception IO of { name: string .... ...} some other arguments that I do not understand. Do I have to assign all these. I mean what do I do after this? exception IO of {inputfile} I usually define exception and then…
700resu
  • 259
  • 6
  • 16
0
votes
1 answer

Output and Input in SML

I am trying to understand TextIO to write and read files line by line. Most resources online start without some introductory texts. I do not have any previous knowledge with file handling and no advanced knowledge with SML. I do not know how to deal…
700resu
  • 259
  • 6
  • 16