Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (*Standard ML Language Guide and Reference
- ML Rules:
- Everything is Immutable, nothing can be changed after the fact
- Type Matters, make sure types don't conflict
- Command Input is usually how things work
- *)
- (*Useful Commands:*)
- it; (*Returns Previous*)
- use "filename.sml"; (*File access*)
- op operation (*Displays the purpose of a function*)
- (*Variable Declaration, note: can be applied to a function*)
- val name = value;
- (*Variable Types:
- int - integer
- real - double
- string- string
- tuple - two things of the same type together (x,y)
- `a - Alpha, everything*)
- val tuple= (5,4)
- #1 tuple; (*Returns the first value of the tuple, 5*)
- val tuple2= ((5,4),(3,2));
- #1 (#2 tuple2); (*Returns the First value of the Second tuple, 3*)
- (*Functions:*)
- val functionName = fn(input:type, input:type) => Code to be run;
- val functionNameAlt = fn(input) => fn(input) => output;
- fun functionName2 (input:type) (input:type) = x*y;
- (*Using Functions*)
- functionName (input,input); (*First Method*)
- functionNameAlt input input; (*Second Method*)
- (*Auxillary Commands that can come in handy*)
- Ceil Floor 5.6; (*Returns 6 or 5*)
- real 5 (*Returns 5.0*)
- explode "String" (*Returns [#"S",#"t",#"r",#"i",#"n",#"g"]*)
- implode [#"S",#"t",#"r",#"i",#"n",#"g"] (*Returns "String"*)
- o (*Chain commands together*)
- (implode o explode) (*Explodes first, then implodes*)
- (*If/Else and the like*)
- if something then something else something (*No Brackets*)
- (*Switch System:*)
- fun Check 0 = true (*First Case: Function Name (the if code) = what happens then*)
- | Check 1 = false (*Function Name (Second case) = What happens*)
- | Check n = false; (*Function Name (n= Everything else/Default) = What happens*)
- (*In Recursion, the first line can be the base case, while the second onwards are for recursive stuff*)
- (*Lists: Tuples that only store stuff of the SAME Data Type, can ONLY access head (first element) and tail (the rest) *)
- [element 1, element 2] (*Standard List*)
- [[list1-a, list1-b], [list2-a, list2-b]] (*List inside a list*)
- hd [1,2,3] (*Returns 1*)
- tl [1,2,3] (*Returns [2,3]*)
- 8::[1,2,3] (*Returns [8,1,2,3]*)
- null [1] (*checks if empty, returns t/f*)
- (*Todo: Data Types and their Declarations
- Anything I might encounter while doing CW*)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement