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

datatype Nt = int | string in ML

When I only have datatype Nt = int | string, sml doesn't complain. But when I also have val n = 6 : Nt, ml doesn't accept 6 as an Nt. Why is this? I do know that, normally there should be data constructers before int and string, but here I'm having…
rem
  • 893
  • 4
  • 18
4
votes
3 answers

SML/NJ - One line length function using foldr

I'm trying to create a length function, similar to the one already included in ML. My restrictions are that it has to be done on one line and use either map, foldl, or foldr. Right now my line of code looks like this: val mylength = foldr ( fn(x,y)…
4
votes
1 answer

The usage of before in ML

ML's before is described in http://sml-family.org/Basis/general.html as a before b returns a. It provides a notational shorthand for evaluating a, then b, before returning the value of a. When I tried to use this command expecting x = 4 and…
prosseek
  • 182,215
  • 215
  • 566
  • 871
4
votes
2 answers

Why are append and uncons for catenable lists merely amortized O(1)?

I took Okasaki's implementation of catenable lists, and refactored it a little bit to avoid Boolean blindness issues. Other than that, the data structure itself remains unchanged: functor CatList (Q : QUEUE) :> CAT_LIST = struct (* private stuff,…
isekaijin
  • 19,076
  • 18
  • 85
  • 153
4
votes
2 answers

How to avoid long pattern match based functions?

When using union types with quite a few constructors I almost always find myself implementing lots of logic in single function, i.e. handling all cases in one function. Sometimes I would like to extract logic for single case to separate function,…
Artur Krajewski
  • 571
  • 1
  • 4
  • 18
4
votes
1 answer

Create sum type in C implementation of OCaml function

Let's say you had a type declaration: type foo = Bar | Baz of int How would you implement a C function to create a Baz? Let's say I declare it like this: external create_baz : int -> foo = "create_baz" Then I would need to fill out this…
brooks94
  • 3,836
  • 4
  • 30
  • 57
4
votes
1 answer

What is the difference between 'a and ''a in SML?

For example: fun example (a:'a list) : list = a will have a signatures of: 'a list -> 'a list What if I define it differently but with same content like fun example (a : ''a list) : list = a its signature will be: ''a list -> ''a list What's…
WreckingBall
  • 1,268
  • 2
  • 10
  • 15
4
votes
1 answer

Shared libraries in Poly/ML

Is it possible to build a shared library using Poly/ML? I want to be able to create a C API for a Poly/ML library, and invoke/load it from different programming languages (e.g., Python). Did anybody try to do that? I know this can be done in…
Leonardo de Moura
  • 21,065
  • 2
  • 47
  • 53
4
votes
1 answer

Can a Standard ML functor take another functor as parameter?

I have an implementation of sets and maps as unbalanced binary trees. Because sets and maps are so alike, I actually only wrote an implementation for maps from scratch, and then trivially implemented sets as maps from keys to units: signature EQ…
isekaijin
  • 19,076
  • 18
  • 85
  • 153
4
votes
3 answers

Is anyone use SML or OCaml for building real world GUI?

After looking at some OCaml graphics related projects it seems that no one using it for building GUI. why ? is there any modern alternatives to those outdated libraries ?
Salah Eddine Taouririt
  • 24,925
  • 20
  • 60
  • 96
4
votes
3 answers

Are there other ways to deconstruct option types in OCaml?

OCaml's option type is really useful in cases where you have functions that might not return anything. But when I use this in many places, I find it cumbersome to handle the Some case and the None case all the time in a match ... with. For…
Jason Yeo
  • 3,602
  • 3
  • 30
  • 38
4
votes
1 answer

How to read from a file in SML?

I'm trying to read text from a file in SML but I can't get it to work. Here's what I'm trying fun read file = let val inStream = TextIO.openIn file in TextIO.StreamIO.input1 inStream end The actual function call input1 is not important,…
Nosrettap
  • 10,940
  • 23
  • 85
  • 140
4
votes
4 answers

EQUALOP error message with SML

I am trying to create a simple function that takes two dates of format int*int*int and return if the first one is older than the second or not. fun is_older (date1: (int*int*int), date2: (int*int*int)) = val in_days1 = (#1 (date1) * 365) + (#2…
Augusto Dias Noronha
  • 854
  • 2
  • 11
  • 20
4
votes
2 answers

In Standard ML, how can you catch an exception like "Error: unbound variable or constructor: foo"?

I have this newbie question: in Standard ML, how can you catch an exception like "Error: unbound variable or constructor: foo"? I tried to do this with the following program: (foo()) handle Error msg => (); But REPL complains: "Error:…
Chao Sun
  • 655
  • 1
  • 6
  • 16
4
votes
1 answer

OCaml used in demonstrations?

I'm looking for examples of usages in OCaml to demonstrate simple properties or theorems. An example may be, given an ocaml definition of binary trees, demonstrate that the maximum number of nodes is 2^(h+1)-1. I have founds such kind of examples…
Fabio Varesano
  • 459
  • 6
  • 13