Pervasives
Types and Type Inference
Include variables that are passed in inside of the type. List basics
Prefix with
List Iterators
Prefix with
List Scanning
Prefix with
List Searching
Prefix with
Lists of pairs
Prefix with
List Sorting
Prefix with
String basics
Prefix with
Maplet rec map ( f : 'a -> 'b) (lst : 'a list) : 'b list = match lst with | [] -> [] | hd :: tl -> f hd :: map f tl ;; fold_leftlet rec foldleft (f : 'a -> 'b -> 'a) (acc : 'a) (lst : 'b list) : 'a = match lst with | [] -> acc | hd :: tl -> foldleft f (f acc hd) tl ;; Different Data Types
Modulemodule type Integer = sig val value : int end module ThreeSig : Integer = struct let value = 3 let is_positive : bool = true end Applying the signature Integer, via ": Integer" restricts ThreeSig makes only "value" public. FunctorTakes in a module and returns a new module. Ex. module Increment ( I : Integer ) : Integer = struct let value = I.value + 1 end Functor can take in multiple modules. Abstraction BarrierIf a signature has a type module type OPERATORS = sig type t end ;; Then it can be overridden in the implementation using the "with" keyword module IntOps : OPERATORS with type t = int = struct type t = int let times = ( ∗ ) let divide = ( / ) let plus = ( + ) let int_to_t x = x end ; ; |
Cheatography
https://cheatography.com
Created By
Metadata
Comments
No comments yet. Add yours below!
Add a Comment
Related Cheat Sheets