sml

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

Standard ml function in datatype problem

I have to create a function about peano numbers defined as the following datatype: datatype 'a peano = P of ('a -> 'a) * 'a -> 'a val zero = P(fn (f, x) => x) The function that I have to implement finds the succesive peano number of the peano parameter P(p). This is what I have written: fun suc (P(p)) = case P(p) of P(fn(f,x)=>x) =>...

how to create a lazy tree in Standard ML

I want to implement a lazy tree in Standard ML with datatype tr = N of int * unit->tr * unit->tr; I tried to use fun form k = N(k,fn()=>form(k+1),fn()=>form(k+3)); as a test of concept, but I get error message saying type mismatch. What would be the proper way of implementing a lazy tree in ML? ...

Conversion from imperative to functional programming [Python to Standard ML]

I have a function specification that states it that should evaluate a polynomial function of one variable. The coefficient of the function is given as a list. It also accepts the value of the variable as a real. For example: eval(2, [4, 3, 2, 1]) = 26 (1*x^3 + 2*x^2 + 3*x^1 + 4*x^0, where x = 2) Here's the function in python, but I'...

SML travelling salesman problem

please anybody having travelling salesman problem solution in Standard ML, plz tell me. I've tried a lot but am not successfull... Thx in advance. ...

Insert element into a tree from a list in Standard ML

I have just started to learn SML on my own and get stuck with a question from the tutorial. Let say I have: tree data type datatype node of (tree*int*tree) | null insert function fun insert (newItem, null) = node (null, newItem, null) | insert (newItem, node (left, oldItem, right)) = if (newItem ...

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

SML/NJ incomplete match

I wonder how people handle nonexhaustive match warnings in the SML/NJ compiler. For example, I may define a datatype datatype DT = FOO of int | BAR of string and then have a function that I know only takes FOOs fun baz (FOO n) = n + 1 The compiler will give a warning stdIn:1.5-1.24 Warning: match nonexhaustive FOO n => ...

difference between infix, infixr, infixl

I read a book that uses infix, infixr, and infixl in the sample programs. I'm wondering what the differences are. I'm guessing that infixr performs operation from right to left, and vice versa. ...

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

Experiences teaching or learning map/reduce/etc before recursion?

As far as I can see, the usual (and best in my opinion) order for teaching iterting constructs in functional programming with Scheme is to first teach recursion and maybe later get into things like map, reduce and all SRFI-1 procedures. This is probably, I guess, because with recursion the student has everything that's necessary for iter...

Including two signatures, both with a 'type t' [Standard ML]

A contrived example: signature A = sig type t val x: t end signature B = sig type t val y: t end signature C = sig include A B end Obviously, this will cause complaints that type t occurs twice in C. But is there any way to express that I want the two ts to be equated, ending up with: signature C = sig type t val x: t ...

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

Creating an AST Tree in Java given another AST Tree

Hi everyone! Currently, I'm working on representing an AST tree I have, written in SML, in Java so I can traverse it in Java whenever I want. I'm wondering if I should just create a Node class in Java that has the data I want to represent, along with a an Array list (List) to represent the children for that specific node? Then, I can ...

Fast Standard ML compiler or bytecode interpreter, with read-eval-print loop, for Linux?

For use with a class I'll be teaching, I'm looking for a fast compiler or bytecode interpreter for Standard ML. I'm looking for fast compile times; any reasonable run time will do. Bonus if the compilation model is simple and clear. Students in the class will also be using MLton to generate good binaries, but MLton is slow to compile...

Preferred book for ML

Hi All, Which book would make the best starter's book for ML (excluding OCaml)? ...

Query on type expressions in ML

All, Here is the type expression which I need to convert to a ML expression: int -> (int*int -> 'a list) -> 'a list Now I know this is a currying style expression which takes 2 arguments: 1st argument = Type int and 2nd argument = Function which takes the previous int value twice and return a list of any type I am having a hard time...

Deriving type expression in ML

All, I want to derive the type expression for the function below in ML: fun f x y z = y (x z) Now I know typing the same would generate the type expression. But I wish to derive these values by hand. Also, please mention the general steps to follow when deriving type expressions. ...

Weight-Biased Leftist Heaps: advantages of top-down version of merge?

I am self-studying Okasaki's Purely Functional Data Structures, now on exercise 3.4, which asks to reason about and implement a weight-biased leftist heap. This is my basic implementation: (* 3.4 (b) *) functor WeightBiasedLeftistHeap (Element : Ordered) : Heap = struct structure Elem = Element datatype Heap = E | T of int * Elem.T...