smlnj

SML/NJ - Pattern Matching an Dynamic Typing

Is it possible to write functions with dynamically typed input parameters? I tried pattern matching, but apparently it does not work like this. I wish to do something like this: fun firstStr (0,n:string) = n | firstStr (b:string,n:string) = if b>n then n else b; Thank you. ...

How to 'fix' the SML/NJ interactive system to use Arrow Keys

Hi all, I'm having some trouble using SML/NJ interactive system, namely, that when I try to use my arrow keys (either left or right to make a correction in the expression I've typed, up to repeat the last expression), my Terminal prints codes. (e.g. ^[[A for up^[[D for left, etc.). While I can still use the system, it makes it very ted...

Line Comments in Standard ML

I'm learning ML, with the SML/NJ dialect. What I'm trying to figure out is if there is a line comment operator. I found the block comment operator, (* ... *), but I really miss line comments. Suggestions? Or am I just stuck with block comments? ...

Polymorphic function as return value and value restriction in SML

Basically, I want to have a function to return a polymorphic function, some thing like this: fun foo () = fn x => x So the foo function takes in a value of type unit and returns a polymorphic identity function and the compiler is happy with that, it gives me: val foo = fn : unit -> 'a -> 'a but once I actually call the foo fu...

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 , 6 )] (first number: name of the node , secend number: name of connected node , third n...

strongly connected components(SCC graph algorithm) in SML

Hi I need to write SCC algorithm in standard ML. but I don't know how to do that. I have following TYPEs whitch has to be uesd in code: type vertex = int type edge = int * int type graph = (vertex * vertex list) list fun dfs (g: graph) (n: vertex): vertex list = let fun helper (todo: vertex list) (visited: vertex list): vertex ...

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 ? ...

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 there any function which can help me? or I have to do it myself? ...

anonymous function in SML

I have this below function and it works (fn x => x * 2) 2; but for this below one, it is not working (fn x y => x + y ) 2 3; can anyone tell me why? or help give me some hint to get it to work. ...

My sml compiler doesnot recognize simple operations on arrays (update(arr,int,int), array(int,int) etc). Help!

Hi, I installed the sml interpreter from here : http://www.smlnj.org/, I used the self extracting .EXE for windows. (I'm running windows7 64 bit) Although simple operations on basic datatypes are working, it is not recognising operations on arrays/vectors (update, array constructor etc). Do i need to install something else as well to ma...

SML/NJ: getting user input

how do i prompt for user input in a running function? ...

sml/nj enumerating solutions

i need help enumerating all possible combinations of length n given a list of strings. example, if my list was ["r","b","g"] and int 2 answer: r r, r b, r g, b r, b b, b g, g r, g b, g g, ...

Pattern matching with reals (Standard ML)

Doing this: fun test a 0.0 = "good" | test a b = "bad"; results in an error, but if I change the 0.0 the error goes away. However, I need to match 0.0 and I'm wondering if and how that can be accomplished. ...

New to ML: How to store return values of type a* a* a*....

Hi I have a program that returns int*int (Example for illustration purposes): fun program(a,b) = (1,2) I want to do something along the lines: fun program(a,b) if a = 0 then (1,2) else val x,y = program(a-1,b) return (x-1, y) Basically, I want to manipulate the tuple that is returned, and then return a modific...

SMLNJ expand # in output

I have the following: val it = DATAX ("hello",DATAX ("world",DATAX #,DATAX #),... Is there a way to make the SMLNJ interpreter expand "#" so that I can see what the exact data is? Thanks! ...

ml traverse help someone please

I am stuck at this problem. I have to return the path from one corner to another corner in a graph. for eg if there is a graph with a b c d corners and i need the path from a to d then i need to traverse a graph which is something like a binary tree. Help me with the code someone.. the corner is defined by Corner datattype datatype Corn...