Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

ML Cheat Sheet, Slides of Programming Languages

ML – Cheat sheet. Definitions val <name> = <newValue>;. e.g.: val x = 25; fun <name> <param> = <expr>;. e.g.: fun addme (a, b) = a + b;.

Typology: Slides

2022/2023

Uploaded on 05/11/2023

agrima
agrima 🇺🇸

4.8

(9)

8 documents

Partial preview of the text

Download ML Cheat Sheet and more Slides Programming Languages in PDF only on Docsity! ML – Cheat sheet  val <name> = <newValue>; e.g.: val x = 25; fun <name> <param> = <expr>; e.g.: fun addme (a, b) = a + b; fun <name> <param> = fn <name_HOF> => <expr>; e.g. fun g a = fn b => a + b; let <defs> in <expr> end e.g. let val x = 1 in x*x end     char (#”x”) string (“x”) int real bool a’ (all types) list  0 => constant 0 (int) _ => any given param matches (a, b, c) => tuple of three elements [a, b, c] => list of three elements (x :: rest) => matches non-emtpy list, x is head (x1 :: x2 :: rest) => matches list 1 elements, ... ... x1 is head, x2 element after head fun fact 0 = 1 | fact n = n * fact (n-1);    ~ (negation) +, -, *, /, div (int quotient), mod (int remainder) ^ (string concat) >, <, <=, >= (for all numbers) =, <> (not for reals!)     List = all same type, >= 2 elements Tuple = all types possible () => tuple [] => emtpy list (= nil) [1] int list with ‘1’ 1 :: 2 :: 3 :: [] => [1, 2, 3] hd(<list>) => first element tl(<list>) => rest elements in list <list1> @ <list2> => combination  explode(<string>) => list of chars implode(<list of chars> => string real(<int>) => real floor(<real>) => rounds down to int ceil(<real>) => rounds up to int round(<real>) => rounds to int ord(<char>) => char to ASCII code chr(<int>) => ASCII code to char map <fun> <list> => apply <fun>... ...to each element in <list> foldr <fun> <starter> <list> => f(x1, f(x2, (...) f(xn, c)) foldl <fun> <starter> <list> => f(xn, f(xn-1, (...) f(x1, c))   if <expr> orelse <expr> andalso <expr> then <expr> else <expr> case <expr> of <value1> => <result1> | <value2> => <result2> | <value3> => <result3>;
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved