[Haskell-cafe] Documenting the impossible
marco-oweber at gmx.de
Sat Jun 14 16:58:32 EDT 2008
> Does anybody think this is a useful idea? If so I'll add a feature request
> ticket to the GHC Trac. But I want to see if folks like the idea first...
Mmmh.. dont' know. Even Java folks don't allow this kind of creeping
bug and I guess they know why. You never want undefined behaviour at
least when using haskell. Because if that error occurs it's hard to
debug, no I don't like that at all.
May I look at your proposal from another view?
Am I right that you ask for not having to run the "fromJust" code to
save some cpu cycles?
Very simple example :
let list = [ (a,a*a) | a <- [1..10] ]
Now getting the square of 4 (standard)
fromJust $ lookup 4 list
Removing the fromJust code thingy leads to:
lookupGoodFaith key ((x,v):xs) | key == x = v
| otherwise = lookupGoodFaith xs
lookupGoodFaith _ (_,v) = v
Where is the difference? I don't even compare the key of the last list
item, because it must match. So you safe some additional cpu cycles..
The same can be implemented for Data.Map etc..
More information about the Haskell-Cafe