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

How to define new signature in sml

I am trying to extend the existing int library to a new library called "bigint". I am keeping the type of the datatype bigint as int list. Basically, I want a function (lets call it getbigint)which accepts any int and store each of its digits in a…
Ankit Shubham
  • 2,989
  • 2
  • 36
  • 61
0
votes
1 answer

An error occurred when I used "CM.make();" in SML,Ubuntu

This is my first time that I used ubuntu and SML/NJ. And this question occurred to me when i used the expression CM.make(): Standard ML of New Jersey v110.76 [built: Tue Oct 22 14:04:11 2013] - CM.make() ; [autoloading] [library $smlnj/cm/cm.cm…
polaris
  • 1
  • 1
0
votes
1 answer

How to compile SML using SMLNJ while the code is in Notepad++?

I'm completely new to SML and I have no idea how to work with anything related to it. I am supposed to use the SMLNJ compiler and I'm currently coding using Notepad++. But how do I compile the program exactly? Do I copy and paste the code in the…
ladanvini
  • 1
  • 1
  • 3
0
votes
0 answers

How to implement general tree in SML?

I am trying to come up with a datatype for a general tree. I tried writing datatype 'a TREE = null | Node of 'a * 'a TREE list; but it didn't work out. My idea is to create a list of child nodes for a parent node and then each of the nodes in…
Ankit Shubham
  • 2,989
  • 2
  • 36
  • 61
0
votes
3 answers

Pass two arguments from command line in sml

I want to pass two arguments from command line. I know how to pass one argument using CommandLine.arguments . val arg1 = CommandLine.arguments(); But how to pass two arguments and use it? Thank you.
Ankit Shubham
  • 2,989
  • 2
  • 36
  • 61
0
votes
2 answers

Where does "#" come from in SML?

I'm trying to make the function which takes string and transforms it to boolean expression. For example:for input ((x10+~1)*x132) it should give times(plus(var 10,compl 1),var 132), but it gives times(plus(var #,compl #),var 132). Where do hashtags…
Tim
  • 37
  • 1
  • 6
0
votes
1 answer

SML NJ - match nonexhausitive - not sure how to handle

I want to define a function that takes 3 parameters and returns a list. The parameters will be of any type and then other two parameters are of lists of any types. This is an example... fun func x [y] [z] = [x, y, z]; Even though the function…
cpd1
  • 777
  • 11
  • 31
0
votes
0 answers

Function from alpha to int

So i have a function that i'm trying to write: fn (x:'a) => ??? (type: 'a -> int) I've tried doing this: fn (x:'a) => (x:int) But obviously that returns a match constraint error. So is there any way I could go about doing this? === EDIT === Is…
madcrazydrumma
  • 1,847
  • 3
  • 20
  • 38
0
votes
2 answers

Number of functions in expression - SML

How many functions are present in this expression? : 'a -> 'a -> ('a*'a) Also, how would you implement a function to return this type? I've created functions that have for example: 'a -> 'b -> ('a * b) I created this by doing: fun function x y =…
Chris
  • 785
  • 10
  • 24
0
votes
1 answer

delete white spaces from char list - sml

I am trying to delete the empty entries from a char list in sml. This is my function but when I try to call it, it doesn't work and brings a fatal error. fun no_spaces([]) = raise Empty | no_spaces(e::f) = if(e = #" ") then no_spaces(f) else…
zeeks
  • 775
  • 2
  • 12
  • 30
0
votes
2 answers

Remove real element from list - SML

I have written the following code: fun remove_element(nil, elem) = raise Empty | remove_element(hd::tl, elem) = if(hd=elem) then tl else hd::remove_element(tl, elem); but that function (which removed element elem from list) works for int. I need…
zeeks
  • 775
  • 2
  • 12
  • 30
0
votes
1 answer

SML/NJ return even integers from int list with foldr

I'm using SML recently and I'm trying to solve a problem. I should create a function that accept an int list and return even int list, I've already created it : fun evens [] = [] | evens [x] = [x] | evens(x::xs) = case x mod 2 of 0 => x::evens…
MHK0
  • 9
  • 4
0
votes
1 answer

Flip Alternate Elements in a List ML

I have written a function that will flip alternate elements in a list, however I have to call it, then call its methods (I'm new to ML so I apologize if I'm using the incorrect terms). I would prefer to just call the function without having to call…
hbteibet
  • 159
  • 1
  • 9
0
votes
1 answer

Incrementing a counter for a word in a list of words and counters

So i have a list of words and counters: [("word1", 1), ("word2", 1)] and I was wondering how I would increment the counter for a word i add into that list, for example: If the word was already in the list, increment the counter for that…
madcrazydrumma
  • 1,847
  • 3
  • 20
  • 38
0
votes
1 answer

Trying to get first word from character list

I have a character list [#"h", #"i", #" ", #"h", #"i"] which I want to get the first word from this (the first character sequence before each space). I've written a function which gives me this warning: stdIn:13.1-13.42 Warning: type vars not…
madcrazydrumma
  • 1,847
  • 3
  • 20
  • 38