2 ms·
Turn on -fdefer-type-errors or use the 7.8 beta with type holes. Write your types first. Write whole programs in the style of lalala :: f g Int -> m q -> z
by tel 13y ago
Turn on -fdefer-type-errors or use the 7.8 beta with type holes. Write your types first. Write whole programs in the style of
lalala :: f g Int -> m q -> z ()
lalala = undefined
and then just check and see if your logic holds water. Then, slowly fill in the implementations and use -XImplicitParams and ?f or 7.8 type holes and _ as placeholders that GHC will tell you the goal types of.
Reflect as much information about side effects into your types as possible. Write new typeclasses to encapsulate smaller APIs like
class Teletype m where
writeLine :: String -> m ()
readLine :: m String
instance Teletype IO where
writeLine = putStrLn
readLine = getLine
echo :: Teletype m => m r
echo = forever $ readLine >>= writeLine
Then now we know what subset of IO `echo` actually uses.
Generally, the type system is your friend and used correctly it lets you write a shitty first draft of your program elegantly and quickly and then get to the hard part of typing it out later.