[Haskell-cafe] Empty Input list

Ketil Malde ketil at malde.org
Tue Mar 13 09:24:37 CET 2012


Kevin Clees <k.clees at web.de> writes:

> Now my function looks like this: 
>
> tmp:: [(Int, Int)] -> Int -> (Int, Int)
> tmp [] y = (0,0)
             ^^^^^
> tmp xs y = xs !! (y-1)

> If the function returns (0,0) it will blocked by another  function. 

Personally, I think using "special" values like this is a code smell,
and indicates poor design.  There are many implicit assumptions, for
instance that (0,0) isn't already a member of the input list, and that
this is correctly handled by surrounding functions.  Generally, it's
much more desirable to encode this in the types, so I would vastly
prefer the Maybe solution in almost all cases, which makes these
assumptions explicit.

-k
-- 
If I haven't seen further, it is by standing in the footprints of giants



More information about the Haskell-Cafe mailing list