[Haskell-cafe] Re: Haskell and the Software design process

Maciej Piechotka uzytkownik2 at gmail.com
Thu May 6 13:44:40 EDT 2010


On Sun, 2010-05-02 at 21:35 -0700, Alexander Dunlap wrote:
> f ys = let xs = (1:ys) in last xs
> 
> uses the partial function "last". Rewriting it in the "non-partial
> style" gives
> 
> f ys = case (1:ys) of
>   [] -> Nothing
>   xs -> Just (last xs)
> 
> 

I guess it is more like

f :: Num a => [a] -> a
f = fromMaybe 1 . safeLast

Regards

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20100506/d4f42d87/attachment.bin


More information about the Haskell-Cafe mailing list