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

Is it possible to do pattern matching without case?

I'm still learning SML, so my apologies if this is a rather dumb question. I was wondering if there was a better way to do pattern matching on some constructs outside of functions. For example, let's say we have a type type coord = int * int *…
Clark
  • 1,357
  • 1
  • 7
  • 18
0
votes
0 answers

What does the operator | mean in ml

I am writing some code in SML and I tackled this function signature (bool | int) -> (int * int) I wondered what's the meaning of this signature
Itai Caspi
  • 39
  • 1
  • 9
0
votes
1 answer

Deriving expression type in SML

I'm kinda new to sml and i'm trying to understand how to derive the expression type. I read Deriving type expression in ML and I'm trying to follow what he did to derive my expression, but I can't understand one passage. The expression I'm trying…
AscaL
  • 183
  • 3
  • 3
  • 11
0
votes
1 answer

SML/NJ Asked to modify my code to use fldr, fldl and map

I'm asked to modify the code I wrote such that in most of the functions I have to use either fldr or fldl Here is the description which includes the test cases. I'm wondering it would be great if you can give me some hint where I should modify to…
Node.JS
  • 1,042
  • 6
  • 44
  • 114
0
votes
1 answer

Implementing Radix Sort in SML

I am trying to implement radix sort in SML via a series of helper functions. The helper function I am having trouble with is called sort_nth_digit, it takes a digit place to be sorted by and a list to sort (n and L respectively). The way I am doing…
0
votes
2 answers

TextIO.outputSubstr() does not write anything

I have a really annoying problem. This function: fun writeAFile() = let val outstream = TextIO.openOut "look_at_me_im_a_file.txt" in TextIO.outputSubstr(outstream,Substring.full("I'm so sad right now :(")) end; Just creates the file…
0
votes
2 answers

convert string to list in Standard ML

Possible Duplicate: Open file in ML(SMLNJ) I have a string value which has value like this: "[(1,2,3),(2,3),(6,8)]" -> string but I want to have these values in int type like this: [(1,2,3),(2,3),(6,8)] -> (int list) list what should I do?is…
JGC
  • 12,737
  • 9
  • 35
  • 57
0
votes
1 answer

Ml file reading limits

I want to read from file but, when I use inputAll or inputLine, it read only 70 character from each line. how can I read from file without limitation ?
student
  • 23
  • 5
0
votes
2 answers

Open file in ML(SMLNJ)

I need to read file in ML (SLMNJ) and save it in some structures. I need to read some data that points to graph declaration: [( 1 , 2 , 13 ),( 2 , 3 , 3 ),( 2 , 4 , 8 ),( 2 , 5 , 4 ),( 3 , 1 , 5 ),( 3 , 4 , 1 ),( 4 , 6 , 5 ),( 5 , 5 , 5 ),( 6 , 4 ,…
Sajad Bahmani
  • 17,325
  • 27
  • 86
  • 108
0
votes
2 answers

Does a list contain alternating elements

I'm trying to write a function which would check, if its elements are alternating. Example of such a list would be: [1,2,1,2,1,2] My attempt so far: fun isAlternating(lst) = case lst of [] => true | x::y::tail => if y <> x …
TheAptKid
  • 1,559
  • 3
  • 25
  • 47
0
votes
1 answer

Sml type confusion

I have this function: fun x (u,v,w) = (u::[v])::w; Which gets a return type of fn: 'a * 'a * 'a list list -> 'a list list Could anyone explain to me how this type is generated from the function? Thank you! Edit: Also, how would I call this…
user2796815
  • 465
  • 2
  • 11
  • 18
0
votes
1 answer

Write a function for comparing playing cards in SML

I have created a data structure for representing playing cards (not sure if it is correct) from a standard deck (52 cards, no jokers). Each card has one of the suits spades, hearts, diamonds or clubs, and one of the ranks ace, 2, 3, 4, 5, 6, 7, 8,…
froli
  • 319
  • 4
  • 18
0
votes
3 answers

SML greater of two lists

Need help with an SML problem I can't seem to solve. Basically I have two list and I need to return the greater from each list. Example call: Greater([8,4,12,5,6],[2,6,14,4,5]); Would return (8,6,14,6). I just started working with lists in SML and…
0
votes
1 answer

Match Non-exhaustive failure

I cannot figure out which case I am missing here,for my functions,can someone help me find which case to consider also so that I do not get the match non-exhaustive error.It is taking time for me to really figure out which part is missing. fun…
Emma
  • 323
  • 3
  • 16
0
votes
1 answer

foldl definition possible wrong in SML/NJ 110.75

The signature of foldl in SML/NJ 110.75 is foldl; val it = fn : ('a * 'b -> 'b) -> 'b -> 'a list -> 'b Also if I give: foldl (op -) 2 [1]; I will take as answer ~1 instead of 1 Can you confirm my findings?
Dragno
  • 3,027
  • 1
  • 27
  • 41