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

Check Whether or Not An Input is a Fibonacci Number

fun isfib(a) = findfib(a,1,1) and findfib(b,x,y) = val z = x + y if b <= 1 then true else if z > b then false else if z = b then true else fib(b,y,z) I'm placing an input into the program and recursively trying to find out if…
user1672578
0
votes
2 answers

foldl operation in SML

I perform the following foldl operation foldl (fn (acc,y) => if acc>y then acc else y+1) 0 [1,3] So, I expect this to produce me an result of 4 but it produces an output of 3. What am I missing ? My trace is something like this: acc: 0 y: 1 acc:…
Sibi
  • 47,472
  • 16
  • 95
  • 163
0
votes
1 answer

Error on type mismatch

I'm writing this function on SML. It is supposed to take a list of possible first name variations (my name is Victoria, so V, Vic, Vicky, etc.) and create records of {altname1, middle, last}, {alt2, middle, last}. So here's my code: fun…
Victoria Ruiz
  • 4,913
  • 3
  • 23
  • 40
0
votes
1 answer

General merge of two lists

I started learning OCaml and I have a problem with a simple function. This is from Developing Application with Objective OCaml Write a general function merge which takes as argument a comparison function and two lists sorted in this order and…
Lukasz Madon
  • 14,664
  • 14
  • 64
  • 108
0
votes
1 answer

pattern matching in ML

I have this code: fun all_except_option2(str : string, strlst : string list) = let fun all_except_option([], result) = NONE | all_except_option(str::T, result) = SOME(List.rev(result) @ T) | all_except_option(H::T, result)…
Alon Rolnik
  • 803
  • 1
  • 7
  • 12
0
votes
2 answers

creat a tuple by removing first element from another tuple in ML

using ML as a programming language we have list and tuple, in the case of lists we can form a list from another list by removing or appending elements from and to the original list, for example if we have: val x = [7,8,9] : int list in REPL we…
mazlor
  • 1,795
  • 4
  • 19
  • 20
0
votes
0 answers

Check if balanced binary tree (standard ml)

The tree datatype is : datatype mobile = Object of int | Wire of mobile * mobile To check if it's balanced I figured out I have to first make a weight function to calculate the weight of the values of each node and then compare left sub tree and…
0
votes
2 answers

Partial sum in functional programming (recursion)

Possible Duplicate: Partial sum in Standard ML? Im new to functional programming and I have an assignment to compute partial sum of a list. E.g. - psum [1,1,1,1,1]; val it = [1,2,3,4,5] : int list Here is the my code so far. However my function…
0
votes
2 answers

Trying to figure out how to run the code Standard Meta Language

I'm trying to figure out how to run the code Standard Meta Language: smallest [5, ~4, 3]; returns ~4 fun smallest L = if null (tl L) then hd L else if hd L < smallest (tl L) then hd L else smallest (tl L);
0
votes
4 answers

how can i find partitions of given list?

how can i find all partitions of list of integers? mostly i need algorithm that uses recursion as i'm gonna implement it in SML. i need just algorithm, i will do coding part by myself. by mistake i wrote code for finding subsets and i don't have too…
unknown
  • 33
  • 1
  • 5
0
votes
1 answer

Print error in SML because of types mismatch

I' trying to print a types value in SML and with no success. Please take a look at the code below and let me know what do I need to do in order to fix this. Thanks. (* Language Definition *) datatype = Id of string; (* Expression Definition…
Alexander Tilkin
  • 149
  • 1
  • 2
  • 13
0
votes
1 answer

Is it possible to check whether a value has a particular type in Poly ML?

In Poly ML, how would you write a function that returned "true" if x was of type 'a, and false if it wasn't?
0
votes
1 answer

Why do I keep getting errors in this piece of code for Standard ML?

I am learning standard ML and I keep getting this error and I am not sure why? Here is the code and the error: > fun in_list(element, list) = if hd(list) = element then true else val tempList = List.drop(list, 1); in_list(element,…
cougar
  • 185
  • 5
  • 15
0
votes
1 answer

the reasons of errors in ML code

The below code is just a kind of prototype. What I want to know is why it fails to compile. fun test(list) = let fun inner(list) = let val from = #1(hd(list)) in if null(tl(list)) = false then…
Q123
  • 319
  • 5
  • 16
0
votes
1 answer

Recursive Error in SML

Can't figure out the error in my function. It is supposed to cycle through a list n number of times, eg: cycle([1, 2, 3, 4, 5, 6], 2) would return [3, 4, 5, 6, 1, 2], cycling the list twice. Here is my code, but I think I am entering into an…