Questions tagged [ml]

A family of functional programming languages including SML, OCaml, and F#. For questions about machine learning, use the [machine-learning] tag please.

ML ("Meta Language") is a family of functional programming languages, created by the Turing award winning computer scientist Robin Milner. It was initially created as the metalanguage for a theorem prover (hence the name), but quickly became used as a general-purpose programming language. One of ML's most famous characteristics is type inference supporting parametric polymorphism.

Some well known dialects of ML are Standard ML (), OCaml () and F# ().

676 questions
0
votes
1 answer

Int list to unit type

I am looking for a function for : int * int * (int -> unit) -> unit. I need this to print a list of numbers. To be more specific, I have a function f num = print ((Int.toString num)^"\n"). So far, I have this: fun for(from,to,f)= if from=to…
jimmu
  • 1,025
  • 1
  • 10
  • 15
0
votes
2 answers

Standard ML - Return the index of the occurrences of a given value in a list

I'm trying to figure out how to return a list of the indexes of occurrences of a specific value in another list. i.e. indexes(1, [1,2,1,1,2,2,1]); val it = [1,3,4,7] int list I'm trying to figure out how lists work and trying to get better at…
Nexion
  • 423
  • 6
  • 18
0
votes
2 answers

Expression type int list does not match function's argument type int list list in SML

I'm making a function that returns a list of fibonacci numbers; however I'm getting the error 7.25-7.37: mismatch on application: expression type int list does not match function's argument type int list list because type int does not…
Electric Coffee
  • 11,733
  • 9
  • 70
  • 131
0
votes
2 answers

Does anybody know how to define a function with several statements in ML?

I am trying to write a function in CPN ML which changes 3 variables, but I don't know how, I just can write one statement. My function should be something like this: fun T1() = x=x+1; y=y+2; k=k-1; when I write this lines of code, I get an error.
sonya kochooloo
  • 114
  • 1
  • 5
0
votes
1 answer

Standard ML exceptions and resources

I would like to release a resource when any exception is raised during the usage of the resource. In C++ this task is easy: I put the release into the destructor, which gets called automatically, whatever happens. In Java one uses the 'finally'…
libeako
  • 2,324
  • 1
  • 16
  • 20
0
votes
1 answer

mapping lists in ML

I have a question about mapping lists in ML the problem seems to repeat itself, I have the current datatypes defined : datatype 'a seq = Nil | Cons of 'a * (unit -> 'a seq); datatype 'a generic_list = List of 'a list |Seq…
yair
  • 95
  • 2
  • 9
0
votes
1 answer

ML compile error in a function

After hours of fixing the following code I got stuck in the following compile error message and no matter what I try, I cannot fix it. Error: syntax error: deleting END RPAREN FUN the code is: fun we (array1 , k, n, fif1) = if Queue.isEmpty fif1…
brera
  • 1
0
votes
1 answer

Map-Function for User-defined Generic Lists

I'm trying to define a new polymorphic type generic_list with two value constructors: List and Seq, and add the function map_function (proc, items) that maps proc over all items. Here is what I have so far: datatype 'a seq = Nil | Cons of 'a * (unit…
0
votes
1 answer

circlarity error in ml

I'm trying to run a function subst(tr, v1, v2) which returns a new ntree where all the values of v1 are replaced by v2 in the output tree. datatype 'a ntree = leaf of 'a | node of 'a ntree list; fun map(f, []) = [] | map(f,x::t)=f(x) ::…
user2285163
  • 11
  • 1
  • 3
0
votes
1 answer

OCAML Recursive function not stopping

And thanks for your help. I'm currently working on an assigment, and I've been stuck with a faulty recursive call. I have a simple CAML-Light function which is supposed to take a list and a size (number), and return a list with a chunk of that list,…
dhcarmona
  • 402
  • 2
  • 10
  • 29
0
votes
1 answer

How can I convert my data type?

I define a data type for a multi list: datatype intnest= INT of int | LIST of intnest list; now I'm trying to write function which can convert this type to main type. for example: [INT 1, INT 2, LIST[INT 6, INT 8]] => [1,2,…
sarah
  • 19
  • 2
  • 7
0
votes
1 answer

caml-light last line not throwing warning

I'm playing with the difference between - as a unary operator and a binary operator in caml-light. let a b = print_int b; print_newline(); ;; let c d e = print_int d; print_newline(); print_int e; print_newline(); ;; a (3 - 4 ) ; c (9 -…
Joe
  • 4,367
  • 7
  • 33
  • 52
0
votes
2 answers

Comparing different datatypes in ML

type Name = string; datatype Expr = Const of int | Var of Name | Neg of Expr | Plus of Expr * Expr | Mult of Expr * Expr | App of Fun * Expr and Fun = Def of Name * Expr (* substitute every x in expression z with expression…
petabyte
  • 1,487
  • 4
  • 15
  • 31
0
votes
1 answer

getting expression doesn't match error

I am trying to implement a node delete function for a Binary Search Tree in SML/nj. However I am getting a constraint error, that I don't understand why... datatype 'a tree = Empty | Node of 'a * 'a tree * 'a tree; datatype 'a stree = STree of ('a *…
omega
  • 40,311
  • 81
  • 251
  • 474
0
votes
1 answer

How to pattern match nested lists?

In sml/nj, I want to create a function that takes a list of non-empty lists, and returns a list of the first elements of each of those non-empty lists. fun get_first [] = [] | get_first x::xs = (hd x)::get_first xs; get_first: ('a list) list -> 'a…
omega
  • 40,311
  • 81
  • 251
  • 474