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

Getting started with Standard ML

I'm looking for some kind of "ML for beginners" guide - google has led me to some obscure mailing lists or way-over-my-head texts so far. The problem is, I have zero functional programming experience so far, and wrapping my head around the concepts…
Toms Mikoss
  • 9,097
  • 10
  • 29
  • 41
5
votes
2 answers

File seeking with SML Basis

Is there a way, using the SML Basis library, to open a file at a specific position? That is, use an operating system call to change the position, rather than scan through the file and throw away the data.
sshine
  • 15,635
  • 1
  • 41
  • 66
5
votes
1 answer

Can I use Gambit-C, Mlton, or Chicken Scheme with Google's Native Client

Those functional language compilers can each compile a functional language to C code. Google's NaCl SDK can compile C. Is it reasonable to create Native Client applications by compiling first with one of those other compilers and running the…
4
votes
1 answer

how to handle divide by zero error in ML

I am new to ML. I need to define a function taking an conditional expression as argument, the problem is if the expression is invalid like "10 div 0 = 0". How can I handle this? For example, the function is defined as following: foo exp1 = if (exp1)…
Jensen
  • 1,653
  • 4
  • 26
  • 42
4
votes
0 answers

HMF inference for recursive functions

I'm working on an implementation of the HMF type system described in this paper by Daan Leijen. The inference algorithm for HMF is defined in section 6.3. Here is the rule for let expressions (pseudocode): infer(Γ, let x = e1 in e2) =     let (θ1,…
Owen Bechtel
  • 138
  • 5
4
votes
1 answer

The Little ML'er - Good training for F#?

I want to get up to speed on F# and was wondering if the book "The Little ML'er" would be of help since F# is based on OCaml which is a derivative of ML. Or, Is ML too different from F# to be of any help? Thanks.
The Internet
  • 7,959
  • 10
  • 54
  • 89
4
votes
1 answer

Declaring type of function in SML

I'm new to ML, but in other languages that use type inference, I have learned the habit of omitting the type of a thing whenever the inference on the right hand side is obvious to a human reader, and explicitly declaring the type of a thing whenever…
Edward Ned Harvey
  • 6,525
  • 5
  • 36
  • 45
4
votes
1 answer

Map function on a list in Standard ML

Based on this definition: An append list is a (simple) implementation of the list abstract data type that makes construction cheap (O(1)), but makes destruction expensive (O(n)). The 'a alistNN and 'a alist types are defined as follows: datatype 'a…
MasterYork42
  • 228
  • 2
  • 11
4
votes
1 answer

Insert function using foldl/foldr

I have been working on a separate function that returns a list that inserts element x after each k elements of list l (counting from the end of the list). For example, separate (1, 0, [1,2,3,4]) should return [1,0,2,0,3,0,4]. I finished the function…
4
votes
1 answer

How to define trees with more than one type in ML programing language

Well, I am asked to do the next thing: To define a binary tree which can contain 2 different types: ('a,'b) abtree and these are the requirements: Any inner vertex (not a leaf) must be of the type 'a or 'b and the leafs have no value. For every…
user550413
  • 4,609
  • 4
  • 25
  • 26
4
votes
1 answer

sml understanding function compositions

I am trying to understand difference between these two; val my_fun = length o List.filter (fn (item) => item = #"a") o String.explode This one can be invoked (my_fun "name" will return 1) and works fine. I am trying to understand why following is…
Can
  • 369
  • 4
  • 16
4
votes
1 answer

Transform ML code to F# (higher-kinded polymorphism)

I am trying to follow up on the paper "Lightweight higher-kinded polymorphism" (https://ocamllabs.github.io/higher/lightweight-higher-kinded-polymorphism.pdf) and I am stuck at transforming this ML code into F# type (_,_) arrow = Fn_plus :…
robkuz
  • 9,488
  • 5
  • 29
  • 50
4
votes
3 answers

foldr/foldl with logic operators in SML

I'm trying to build a function in SML using foldr or foldl that will return the logic or and logic and of all elements in a list. I've tried in this way, using and and or: fun band x = foldr (op and) true x; fun bor x = foldr (op or) false x; And…
4
votes
1 answer

Match non exhaustive in sml

fun p( x::xl ) = if x::xl = [] then [] else [0]; It received a Warning: match non exhaustive. x::xl => ... What I want to do is: p( [] ) = [] When I do this, it gives a uncaught exception Match [nonexhaustive match failure]
Jam
  • 113
  • 2
  • 7
4
votes
2 answers

OCaml functions passing in one less argument

I'm looking at solutions for a homework and the code implements an OCaml function that takes in two arguments but when its called, it's only passed one argument. let rec func2 r x = match r with | [] -> [] | (nt,rhs)::t -> if nt = x then…
cheng
  • 1,264
  • 2
  • 18
  • 41