haskell-cafe@haskell.org
[Top] [All Lists]

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

Subject: [Haskell-cafe] Re: Haskell and the Software design process
From: Maciej Piechotka
Date: Thu, 06 May 2010 18:44:40 +0100
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

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@xxxxxxxxxxx
http://www.haskell.org/mailman/listinfo/haskell-cafe
<Prev in Thread] Current Thread [Next in Thread>