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

Show Multiple occurrences of items in a list, sml

I'm trying to show the indices of all multiple occurrences for an element in a list. in standard ml. but my code show the empty list :( this is my code: fun index(item, xs,ys) = let fun index'(m, nil , ys) = ( SOME (ys) ) | index'(m, x::xr ,…
Blue Moon
  • 3
  • 2
-1
votes
1 answer

SML interpreter.My Div func is working but i am having issue with my Minus func. I want it to give an error when the passed error is not a number

datatype exp = Int of int | Minus of exp * exp | Div of exp * exp; datatype value = CVal of int | FnVal of string * exp * (string * value) list | Error of string; fun eval (Int x) _ = CVal x | eval (Div (e1,…
-1
votes
1 answer

SMLNJ list traversion

How would I go about traversing a list in SMLNJ. I have been at this for 3 hours now and I cannot figure it out for the life of me. So just to traverse and print a list out. In the simplest way [5,2,3] would print out 5 2 3 or a list variant of…
-1
votes
1 answer

Compare real list in sml

For the next code I'm getting an error: fun epoly(L:real list, x:real)= = if L = [] then 0.0 else (epoly(tl(L:real list), x:real));; Error: stdIn:42.1-42.57 Error: operator and operand don't agree [equality type required] operator domain: ''Z *…
user9994979
-1
votes
2 answers

Inserting LPAREN error in SML

I'm writing SML code to calculate the number of living people, dead people, and zombies over time, given specific formulas. I've put my code into a ".sml" file and I open it in SMLNJ. The errors I get are as follows. zombies.sml:36.3 Error: syntax…
Paradox
  • 19
  • 1
  • 6
-1
votes
1 answer

Why does my while loop not terminate in this functional language?

I'm trying to build a standard ML program using both imperative and functional concepts, and write the contents to a file. But my while loop doesn't seem to terminate and instead prints the same value continuously. fun writeImage image filename = …
oldselflearner1959
  • 633
  • 1
  • 5
  • 22
-1
votes
1 answer

SMLNJ Parse list of strings into list of tuples with multiple datatypes

I have a list of strings that I would like to parse into a list of tuples. more specifically: val strlist = ["1, 2, 3, 'hello', 4, 5, false, 6, [1, 2, 3], [1, 2]", "6, 1, 3, 'world', 4, 5, true, 4, [1, 2], [4, 7, 5]", .…
patyx
  • 324
  • 1
  • 3
  • 17
-1
votes
1 answer

Standard ML running multiple functions in a loop (Using recursion or any other means)

I have defined three different functions that will perform calculations and return a value. These functions will consistently be redefining a variable until a specific condition is reached. I am having issues getting these to run in a "loop"…
Busta
  • 81
  • 9
-1
votes
1 answer

Call a Python Function within SML

I am trying to call a function from a python file I wrote in SML. I am receiving a tycon mismatch error and I don't understand why. This is my SML code fun interpreter(inFile: string, outFile: string)= let val s = interpreter(inFile,…
arizq29
  • 11
  • 5
-1
votes
1 answer

How to change the datatype of an existing tree in SML?

I need to solve this problem. I really have no clue. Any help would be greatly appreciated. I guess a traversal needs to be done but I have no idea how to attack this problem. Thanks in advance. Consider again the following 1st datatype definition…
-1
votes
1 answer

Creating a "mailbox" like abstraction in Concurrent ML

I am trying to create a bounded "mailbox" like abstraction in Concurrent ML. My abstraction has 2 channels for taking values in (which are later stored in a list called "buffer") and for sending values out. CM.make "$cml/cml.cm"; open CML; fun…
-1
votes
2 answers

How to define a function having format fn : ('a -> 'b) -> 'a list -> unit

I need to write a function printGenList that take a function f and a list l and applies f on every element of l recursively. I tried this - fun printGenList (f (int)list):unit = ( f(HD list); printGenList (f) (TL list) ); I could do the same…
Vibhav Gupta
  • 71
  • 1
  • 8
-1
votes
1 answer

In SML, how do I remove the first occurence of a pattern from a list and then return the removed item and the rest of the list?

I'm trying to write an SML function that takes as parameters a list and an item. If the item is present, the function should return a tuple containing the list without the first such occurence of that item and the item just removed. If there are no…
user2309462
  • 126
  • 8
-1
votes
1 answer

SML curried function which takes a list and a positive number k as inputs and checks whether any element occurs exactly k times in it.

write a curried function f1 which takes a list and a positive number n as inputs and checks whether any element occurs exactly n times in it. eg.- f1 [1,2,1,3] 2; val it = true : bool - f1 [1,2,1,3] 3; val it = false : bool
Hailee
  • 23
  • 3
-1
votes
1 answer

Is this the same as finding the max starting at the tail of the list?

I'm wondering if this would be considered starting your comparisons at the tail end instead of the head? fun maxTail [] = raise Empty | maxTail [x] = x | maxTail (x::xs) = let val y = maxTail xs in if x > y then x…
user2796815
  • 465
  • 2
  • 11
  • 18
1 2 3
57
58