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
6
votes
2 answers

Why are ML/Haskell datatypes useful for defining "languages" like arithmetic expressions?

This is more of a soft question about static type systems in functional languages like those of the ML family. I understand why you need datatypes to describe data structures like lists and trees but defining "expressions" like those of…
nek28
  • 259
  • 1
  • 2
  • 6
6
votes
1 answer

Is function application evaluation order deterministic in SML?

In OCaml, evaluation order of function application is unspecified (aka non-deterministic). In Standard ML, is it also non-deterministic or deterministic? Can you provide a reference to the spec section that clarifies? Edit: for those of you coming…
jayphelps
  • 15,276
  • 3
  • 41
  • 54
6
votes
2 answers

Example of nested signatures in OCaml?

In OCaml, you can nest signatures: module type FOO = sig module type BAR (* … *) end I was just wondering if anyone had any examples of this in use, since I can’t think of any places where it would be needed. I imagine it’s probably useful in…
Andy Morris
  • 720
  • 3
  • 10
6
votes
4 answers

Is there a standard higher order function for applying a transformation several times?

I'm thinking of a function like this: > let applyN (initial : 't) (n:int) (f : 't -> 't) = seq {1..n} |> Seq.fold (fun s _ -> f s) initial;; val applyN : initial:'t -> n:int -> f:('t -> 't) -> 't > applyN 0 10 (fun x -> x + 1);; val it : int =…
vidi
  • 2,056
  • 16
  • 34
6
votes
1 answer

Finding an item in a list and returning its index - OCaml

I've wrote the following function to find a given item "x" in a given list "lst" and return its index if it's found, otherwise it would return an error: exception Failure of string let rec func x lst c = match lst with | [] -> raise(Failure…
Kyle
  • 154
  • 1
  • 2
  • 13
6
votes
1 answer

Pass operator to function in ML

How can I pass an operator to a function in ML? For example, consider this pseudocode: function (int a, int b, operator op) return a op b Here, an operator can be op +, op -, etc. How can I do this in ML?
Chin
  • 19,717
  • 37
  • 107
  • 164
6
votes
3 answers

Standard ML repeat last command, left arrow?

I am learning standard ML using its interpreter. Sometimes I make typo and just want to repeat the previous command like in Linux shell. However, up arrow will end up with printing special characters on the screen. Sometimes I want to go back left…
Alfred Zhong
  • 6,773
  • 11
  • 47
  • 59
5
votes
2 answers

Does SML (Poly) have a CL-like REPL?

Here's a quote from Ron Garret's "Lisping at JPL": "Debugging a program running on a $100M piece of hardware that is 100 million miles away is an interesting experience. Having a read-eval-print loop running on the spacecraft proved invaluable in…
5
votes
3 answers

Is it possible to create a "generic" function in Standard ML?

I would like to create a function remove_duplicates that takes a list of any type (e.g. can be an int list or a bool list or a int list list or a whatever list) and returns the same list without duplicates, is this possible in Standard ML?
user11719516
5
votes
1 answer

Changing identical types in OCaml

Suppose I have a function list_fun : int_list -> string list and in that function I use a StringSet that I define as module StringSet = Set.Make(String). I try to have the function return Set.elements s and get a string list but instead I get a…
Aymon Fournier
  • 4,323
  • 12
  • 42
  • 59
5
votes
1 answer

Standard ML fibonacci overflow

I've been messing around with learning some functional programming and decided to pick up ML as my vehicle to do so. It's only been a few days since I picked up ML and maybe have spent about 5-6 hours total working through some problems. Anyway, on…
Matt Matero
  • 119
  • 1
  • 10
5
votes
3 answers

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…
name_masked
  • 9,544
  • 41
  • 118
  • 172
5
votes
1 answer

Binomial Heaps: proof that merge runs in O(log n) time

I am reading through Okasaki's Purely Functional Data Structures and am trying to do some of the exercises. One of them is to prove that binomial heap merge takes O(log n) time where n is the number of nodes in the heap. functor BinomialHeap…
Justin Raymond
  • 3,413
  • 2
  • 19
  • 28
5
votes
4 answers

Explain ML type inference to a C++ programmer

How does ML perform the type inference in the following function definition: let add a b = a + b Is it like C++ templates where no type-checking is performed until the point of template instantiation after which if the type supports the necessary…
5
votes
2 answers

Standard ML Proof of soundness?

Regarding the Standard ML compiler, my question is,even though ML itself is formally defined making it possible to prove deterministic evaluations of programs, isnt the compiler itself written in C, which is not formally defined, at least not all of…
SJP
  • 1,330
  • 12
  • 21