[Haskell-cafe] let vs. where
Derek Elkins
derek.a.elkins at gmail.com
Tue Nov 13 21:52:46 EST 2007
On Tue, 2007-11-13 at 13:51 -0800, Dan Piponi wrote:
> On Nov 13, 2007 1:24 PM, Ryan Ingram <ryani.spam at gmail.com> wrote:
> > I tend to prefer where, but I think that guards & function declarations are
> > more readable than giant if-thens and case constructs.
>
> Up until yesterday I had presumed that guards only applied to
> functions. But I was poking about in the Random module and discovered
> that you can write things like
>
> a | x > 1 = 1
> | x < -1 = -1
> | otherwise = x
>
> where 'a' clearly isn't a function. Seems like a nice readable format
> to use. Probably everyone except me already knew this already though.
Yep.
Haskell and Haskell code very often avoids special/corner cases.
There's no reason that shouldn't work so it does. Other examples are:
nullary fundeps, class Foo a | -> a where ... ; non/record syntax for
pattern matching, case x of App {} -> ... ; guards pretty much
everywhere
More information about the Haskell-Cafe
mailing list