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
8
votes
1 answer

How to understand segmented binomial heaps described in

In chapter 6.3.1 of the thesis Purely Functional Data Structures, says: Then, whenever we create a new tree from a new element and a segment of trees of ranks 0... r-1, we simply compare the new element with the first root in the segment…
wenlong
  • 1,434
  • 1
  • 13
  • 22
8
votes
1 answer

Examples of the difference between `prompt/control` and `shift/reset`

I am not sure I understand the difference between the delimited continuation operator pairs prompt/control and reset/shift. I understand some basic examples of use, but in those examples their behavior is the same. I have found this example in "On…
johjs
  • 81
  • 3
8
votes
3 answers

Learning/using ML. Which system should i use?

I want to learn and use ML but there are many compilers out there. I need: speed low memory usage threading mutable arrays and record types continuations ready for production code easy ffi up to date ... helpful libraries portable to some degree I…
knivil
  • 916
  • 5
  • 10
8
votes
3 answers

Understanding the type error: "expected signature Int*Int->Int but got Int*Int->Int"

The comments on Steve Yegge's post about server-side Javascript started discussing the merits of type systems in languages and this comment describes: ... examples from H-M style systems where you can get things like: expected signature…
devstopfix
  • 6,698
  • 4
  • 34
  • 32
8
votes
2 answers

Do ML family compilers do any sophisticated optimization for tail calls?

I (believe) the following function definition is tail-recursive: fun is_sorted [] = true | is_sorted [x] = true | is_sorted (x::(y::xs)) = if x > y then false else is_sorted (y::xs) Trivially, it's equivalent to the following…
Zach Halle
  • 321
  • 1
  • 9
8
votes
2 answers

Lexical Scope in Python vs ML

I'm in a big dilemma, take the following code written in ML: val x = 1 fun f(y) = x + y val x = 2 val y = 3 val z = f (x + y) The value of z is 6. Now if I write the same code in python the value of z would be 7. And both languages claim(actual the…
Mihai Vinaga
  • 1,059
  • 2
  • 10
  • 27
8
votes
3 answers

How to add readline support in polyml interpreter?

I found that polyml is the implementation of ML that can be easily installed on Ubuntu (named polyml in repository and can be executed with poly). I am following the A Gentle Introduction to ML by Andrew Cumming. After few minutes of experiment with…
Santosh Kumar
  • 26,475
  • 20
  • 67
  • 118
8
votes
1 answer

N-ary tuples vs pairs

In Ocaml, tuples with different arities have different type and value constructors: # let a = (1, 2, 3);; val a : int * int * int = (1, 2, 3) # let b = (1, (2, 3));; val b : int * (int * int) = (1, (2, 3)) Note that second example (b) is more…
John Rivers
  • 1,307
  • 10
  • 20
8
votes
4 answers

How to use AND operator in IF statements in SML

I am new to SML. How do I use the AND operator inside IF statements? Here is my code: val y = 1; val x = 2; if (x = 1 AND y = 2) then print ("YES ") else print("NO "); My error is: stdIn:66.9-67.3 Error: unbound variable or constructor:…
Alexander Tilkin
  • 149
  • 1
  • 2
  • 13
8
votes
1 answer

Overloading in Ocaml

I know that OCaml does not support overloading. Then, instead of overloading, what can we do to work this around? 1) use polymorphism instead? 2) give different functions different names? 3) put functions of the same name in different modules? Which…
user1382007
  • 81
  • 1
  • 3
7
votes
4 answers

return a list of element from a list in OCaml

I am new to OCaml, and I am now trying to implement a function that returns a list of elements of a given list x at indexes in list y. For example, that function should perform the following computation: [5,6,7,8], [0, 3] => [5, 8] I am not sure how…
Allan Jiang
  • 11,063
  • 27
  • 104
  • 165
7
votes
1 answer

what are curry and uncurry in high-order functions in ML

fun curry f x y = f (x, y); fun uncurry f (x, y) = f x y; fun compose (f, g) x = f (g x); I understand compose function, but not quite understand curry and uncurry in ML. Can anyone explain these? Also, what do the following two lines mean? (1)…
Jensen
  • 1,653
  • 4
  • 26
  • 42
7
votes
2 answers

What does pipe ( | ) mean in ML Programming?

For example the following function: fun fac (0 : int) : int = 1 | fac (n : int) : int = n * fac (n - 1) Or in the function: fun even 0 = true | even x = odd(x-1) and odd 0 = false | odd x = even(x-1); I have little experience with ML and…
Ryan Smith
  • 709
  • 1
  • 7
  • 14
7
votes
1 answer

Encode rank-2 polymorphism equivalent in SML

runST is a Haskell function that statically constrains the usable lifetime of a resource through types. To do this it uses rank-2 polymorphism. Standard ML's simpler type system only offers rank-1 polymorphism. Can Standard ML still use types to…
Alex Celeste
  • 12,824
  • 10
  • 46
  • 89
7
votes
3 answers

Weak Polymorphism in OCaml

I am a little confused about weak polymorphism in OCaml. Please see the following snippet, where I define a function remember: let remember x = let cache = ref None in match !cache with | Some y -> y | None -> cache := Some x;…
1 2
3
44 45