In normal Haskell you can use what is possibly the most obscure Haskell98 feature, the default keyword, to modify how type defaulting works, and resolve ambiguities — but only for numeric classes. The result is less type signatures, as below:

default(Double)

main = print $ 2 + 1

In ghci, this defaulting has been extended to the Eq, Ord and Show classes, so we can write, in ghci:

> reverse []
[]

and ghci will find the right Show instance. Now, in lambdabot, we can evaluate user’s code in the irc channel, but often the user has to add extra types to have the right Show instance found:

dons:: > reverse []
lambdabot:: Add a type signature
dons:: > reverse [] :: [()]
lambdabot:: []

This is annoying. What would be really nice is if the defaulting mechanism used by ghci was available to userland Haskell, by a -fglasgow-extension of the default keyword mechanism.

Update Simon has now kindly added a new flag to GHC, “-fextended-default-rules”, which does exactly this. Lambdabot won’t be second class anymore :)

About these ads