Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 1+2*3;;
- - : int = 7
- # let pi = 4.0 *. atan 1.0;;
- val pi : float = 3.14159265358979312
- # let square x = x *. x;;
- val square : float -> float = <fun>
- # square(sin pi) +. square(cos pi);;
- - : float = 1.
- # 1.0 * 2;;
- Error: This expression has type float but an expression was expected of type int
- # let rec fib n =
- if n < 2 then n else fib(n-1) + fib(n-2);;
- val fib : int -> int = <fun>
- # fib 10;;
- - : int = 55
- (*FUNCIONES*)
- # let <f> = function <x> -> <e>
- # let <f> <x> = <e>
- # function x ->
- if x>=0 then x
- else -x;;
- # let abs x = if x >= 0 then x else –x;;
- (*FUNCIONES RECURSIVAS*)
- # let fact n = if n = 0 then 1
- else n * fact(n-1);;
- ----------------------------------------------------------------------
- (*Forma correcta*)
- # let rec fact n = if n=0 then 1
- else n * fact(n-1);;
- (*LISTA*)
- # [1;3;3] @ [7,9];; //concatenación
- # list.lenght [true:false];;
- # list.map //aplica una función a toda una lista
- # let par n = n mod = 0;;
- # list.filter par [3;7;9;12;3;4] //sale la lista de pares
- # list.for_all //devuelve un bool si todos son pares
Advertisement
Add Comment
Please, Sign In to add comment