3 ms·
A t for a type variable. I sometimes name variables to the data structure that they are holding, e.g. p for pair, h for heap. The names x, y and z for things th
by jules 16y ago
A t for a type variable. I sometimes name variables to the data structure that they are holding, e.g. p for pair, h for heap. The names x, y and z for things that have a generic type, and xs ("axes"), ys ("whys"), zs ("zeds") for collections of general things (and xss for collections of collections of things).
For example, an F# pairing heap:
type 't heap = Empty | Heap of 't * 't heap list
let findmin (Heap(x,_)) = x
let merge h1 h2 =
match (h1,h2) with
| Empty,h | h,Empty -> h
| Heap(x,h1s),Heap(y,h2s) -> if x < y then Heap(x,h2::h1s) else Heap(y,h1::h2s)
let deletemin (Heap(_,hs)) = List.fold merge Empty hs
let insert h x = merge h (Heap(x,[]))
First line: t for type. Second line: x for something of generic type t. Third line: h1 and h2 for heap. Fifth line: h1s and h2s for lists of heaps corresponding to h1 and h2. This saves time coming up with names, and it ends up being more readable if you're used to it. Of course these short names will only be used for variables that are used internally in a function, not for function names and such.