Skip to content

Instantly share code, notes, and snippets.

@paulcc
paulcc / sketch.rb
Created June 29, 2012 16:04 — forked from mattwynne/sketch.rb
pseudo-haskell
class Valid a where
valid :: a -> OkF Errors
class Valid a => Persist m a where
save :: a -> m (OkF a) -- or errors
data User = User {name :: String}
data Organisation = Organisation {name :: String, users :: [User]}
-- see below for commentary
makeUpTo :: Int -> [String] -> [String]
makeUpTo n = mlu []
where
mlu pre [] = [pre]
mlu [] (w:ws) = mlu w ws
mlu pre (w:ws) | length pre + 1 + length w <= n = mlu (pre ++ ' ' : w) ws
| otherwise = pre : mlu [] (w:ws)