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
15
votes
4 answers

Better to use "and" or "in" when chaining "let" statements?

I realize this is probably a silly question, but... If I'm chaining a bunch of let statements which do not need to know each other's values, is it better to use and or in? For example, which of these is preferable, if any: let a = "foo" and b =…
koschei
  • 819
  • 6
  • 13
14
votes
1 answer

Church-Rosser Theorem Example in a Functional Programming Language

I have seen multiple references to the Church Rosser theorem, and in particular the diamond property diagram, while learning functional programming but I have not come across a great code example. If a language like Haskell can be viewed as a kind…
13
votes
7 answers

How Functional language are different from the language implementation point of view

There is the whole new paradigm of "functional programming", which needs a total change of thought patterns compared to procedural programming. It uses higher order functions, purity, monads, etc., which we don't usually see in imperative and…
dinsim
  • 2,395
  • 5
  • 24
  • 32
11
votes
2 answers

Can I build a graphical interface from ocaml toplevel?

À few questions regarding the interactive toplevel and graphical UI programming: Is it possible to build a graphical interface dynamically from ocaml toplevel? It is possible to use the Graphics library too?
11
votes
1 answer

Printing only print output with SML/NJ

I'm trying to use SML/NJ, and I use sml < source.sml to run the code, but it prints out too much information. For example, this is the source.sml: fun fac 0 = 1 | fac n = n * fac (n - 1) val r = fac 10 ; print(Int.toString(r)); This is the…
prosseek
  • 182,215
  • 215
  • 566
  • 871
11
votes
3 answers

Standard ML functor examples

Functors in Standard ML are related to the module system and can generate structures based on other structures. An example of a functor generating list combinators for various types of lists is given below, but this example has a problem: The…
sshine
  • 15,635
  • 1
  • 41
  • 66
11
votes
2 answers

OCaml - Pattern matching with list reference in a tuple

is there a cleaner way of doing this? I'm trying to do pattern matching of a (a' option * (char * nodeType) list ref the only way I found was doing this : match a with | _, l -> match !l with | (c, n)::t -> doSomething Wouldn't there be a way…
Pacane
  • 20,273
  • 18
  • 60
  • 97
10
votes
2 answers

How to annotate let binding as deprecated in OCaml?

I want to annotate a function from an external library as deprecated, to ensure it will not be use in my project. Let's assume the library offers the following module: module Lib : sig val safe_function : int -> unit val unsafe_function : int ->…
authchir
  • 1,605
  • 14
  • 26
10
votes
6 answers

Why do Maybe/Optional types use a Just/Some type instead of the actual type?

In Idris, the Maybe type is defined as followed: data Maybe a = Just a | Nothing It's defined similarly in Haskell: data Maybe a = Just a | Nothing deriving (Eq, Ord) Here's the ML version: datatype 'a option = NONE | SOME of…
Trevor Hickey
  • 36,288
  • 32
  • 162
  • 271
10
votes
3 answers

GUI for Standard ML?

I started learning Standard ML recently out of curiosity. So what I know is that is has an efficient compiler (MLton) which allows us to freely use abstractions without worrying about performance. It would be perfect if I could do some GUI…
Phil
  • 5,595
  • 5
  • 35
  • 55
9
votes
3 answers

Differences between data/type constructors and functions?

Could anyone explain to me what are the differences between data/type constructors and functions? Haskell mix them and give us a universal interface (all looks like functions, in particular, we can partially apply them), while the ML family…
day
  • 2,292
  • 1
  • 20
  • 23
9
votes
0 answers

Which languages, if any, implement rank-2 parametric polymorphism and why not ML?

In section 23.8 of his book Types and Programming Languages, Benjamin C. Pierce writes the following: Another well-studied restriction of System F is rank-2 polymorphism, introduced by Leivant (1983) [...]. A type is said to be of rank 2 if no path…
authchir
  • 1,605
  • 14
  • 26
9
votes
1 answer

'How to use higher order functors properly?' or 'How to have serious fun with funsigs?'

Motivation For the life of me, I cannot figure out how to use higher order functors in SML/NJ to any practical end. According to the SML/NJ docs on the implementation's special features, it should be possible to specify one functor as an argument…
Shon
  • 3,989
  • 1
  • 22
  • 35
9
votes
4 answers

Pattern matching functions in OCaml

Can everyone explain to me this piece of code ? let safe_division n = function | 0 -> failwith "divide by 0" | m -> n / m When I excute safeDiv 3 0 , what is the m and n in this case ? In general case, when does the function match the first and…
Hoan Dang
  • 2,222
  • 5
  • 27
  • 36
9
votes
1 answer

Inferring recursive expressions using Hindley Milner & constraints

I am trying to infer the type of the following expression: let rec fix f = f (fix f) which should be given the type (a -> a) -> a After using the bottom up algorithm (described in generalizing hindley-milner type inference algorithms) with the…
user181351
1
2
3
44 45