-- Convert numbers to Roman -- Sometimes, complicated if and case constructs can be encoded as data, -- thus leaving the algorithm itself a simple 'map' operation -- In the following example, the variable 'digitPattern' encodes the -- 'subtraction rule' and 'five rule' of the roman number system -- which otherwise would have to be encoded with tedious 'if' and 'case' -- See jsfiddle.net / rplantiko/ehL5qwpq/ for the original JS version toRoman n = let digitPattern = [ [], [0], [0,0], [0,0,0], [0,1], [1], [1,0], [1,0,0], [1,0,0,0], [0,2]] symbols = "IVXLCDMↁↂ" r( n, s ) | n < 10 = map (\x->symbols!!(x+2*s)) (digitPattern!!n) | n >= 10 = r( div n 10, s+1) ++ r( mod n 10, s) in r(n,0) main = print(toRoman 3896 )