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

SML - Using map to return combined results

I have these functions: fun IsDivisible(t, t2) = if t mod t2 > 0 then true else false; fun IsDivisibleFilter(ts, t) = List.filter(fn x => IsDivisible(x, t)) ts; fun IsDivisibleMap(ts, ts2) = map(fn x => IsDivisibleFilter(ts, x))…
Lance_P
  • 299
  • 2
  • 16
0
votes
1 answer

How does SML evaluate the arguments passed into currying function?

I write two different pieces of code trying to figure out the substitution v.s. evaluation order SML uses with respect to function arguments. But the results confused me a lot. The toy function is as below fun pow x y = if y=0 then 1 else x * (pow x…
0
votes
1 answer

Why am I getting "unbound variable or constructor" in my SML program

I have written a method to return the first element in a list that satisfies a function (passed in via currying). The function returns NONE or SOME depending on whether or not the element satisfies a condition. I'm using Pattern Matching However,…
Dave
  • 8,095
  • 14
  • 56
  • 99
0
votes
1 answer

Standard ML multiple condition statement

I am about finished with a script I am writing but I have one last condition statement to add to my function. fun whileloop (x:real,a:int,b:real) = if (a<1) then (x,a,b) else whileloop(x+1.0,a-1,b-1.0) This is my current loop I have…
Busta
  • 81
  • 9
0
votes
1 answer

Returning two variables in SML

I have a function below that uses variable X and variable A. How can I return both of these variables to be able to use these values further down the program. val a = 1000; val x = 5; fun test (x,a) = if (a<1) then( x) else( …
Busta
  • 81
  • 9
0
votes
1 answer

Creating an array in smlnj

Ok, let me start off by saying I am a super newbie in Standard ML. I am literally just beginning to program in this language. To be honest with you, I don't plan on digging too deep in this language. I just need to accomplish a one-time task and…
Busta
  • 81
  • 9
0
votes
2 answers

how to split a list into two lists in which the first has the positive entries and the second has non-positive entries-SML

I am a new to SML and I want to write a function splitup : int list -> int list * int list that given a list of integers creates from two lists of integers, one containing the non-negative entries, the other containing the negative entries. Here is…
DennngP
  • 37
  • 8
0
votes
1 answer

Convert "char list array" to "char array array" in SML

I am trying to convert the following variable: - final "in1.txt"; val it = [|[#"S",#".",#".",#"."],[#".",#".",#".",#"."],[#"W",#".",#"X",#"W"], [#".",#".",#"X",#"E"]|] : char list array from 'char list array' to 'char array array' in SMLNJ. The…
Zehanort
  • 458
  • 2
  • 10
0
votes
1 answer

2D map to graph in Sml

I have a 2D map as input from a file ,line by line and I want to save it and run a Bfs or Dijkstra to find the shortest path from Start (marked as S ) to end (marked as E),what's the proper structure to save the information? My implementation in c++…
orfeas
  • 1
0
votes
1 answer

How to output a string list to a textfile in SML?

I am trying to write a method that when called, given a string list and the name of the output file, will output each element to the output file in SML. I have tried this, but it doesn't seem to work. fun quit(outFile: string, list: string list) = …
arizq29
  • 11
  • 5
0
votes
1 answer

Defining types in SML?

If I want to check if a string starts with a letter and the rest of the characters can either be a letter or number, how would I define a datatype that is defined by those conditions? Or would pattern matching be the better route and if so, how…
arizq29
  • 11
  • 5
0
votes
1 answer

SML: Function composition with isSome

I have the following examples and they do not work even though the types do matchup with each other - isSome; val it = fn : 'a option -> bool - SOME; val it = fn : 'a -> 'a option - val my_converter = (fn x => if x = 5 then SOME x else NONE); val…
Har
  • 3,727
  • 10
  • 41
  • 75
0
votes
1 answer

Adding items to list SML

I'm very new to SML and I'm trying to add some items to a list fun foo(inFile : string, outFile : string) = let val file = TextIO.openIn inFile val outStream = TextIO.openOut outFile val contents = TextIO.inputAll file val lines = String.tokens (fn…
dws
  • 3
  • 2
0
votes
1 answer

Call a Python file in a SML program?

I was wondering if it is possible to call a python file in an SML program, and if so how can you do it? I have tried researching how to do this, but have only found documentation on how to call other SML files.
arizq29
  • 11
  • 5
0
votes
2 answers

SML splitting string on first space

As of right now I am reading in an entire input file using inputAll and then using String.tokens to split each word at every occurrence of space. val file = TextIO.openIn input val _input = TextIO.inputAll file val _ = TextIO.closeIn…
Truth
  • 31
  • 1
  • 8