[Haskell-cafe] Bool as type class to serve EDSLs.
nicolas.pouillard at gmail.com
Fri May 29 03:41:41 EDT 2009
Excerpts from Bulat Ziganshin's message of Thu May 28 15:07:02 +0200 2009:
> Hello Lennart,
> Thursday, May 28, 2009, 11:57:09 AM, you wrote:
> > -- | Generalization of the 'Bool' type. Used by the generalized 'Eq' and 'Ord'.
> > class Boolean bool where
> > (&&) :: bool -> bool -> bool -- ^Logical conjunction.
> > (||) :: bool -> bool -> bool -- ^Logical disjunction.
> i use another approach which imho is somewhat closer to interpretation
> of logical operations in dynamic languages (lua, ruby, perl):
I tend to prefer Monoid:
(|||) :: (Monoid a, Eq a) => a -> a -> a
a ||| b | a == mempty = b
| otherwise = a
(&&&) :: (Monoid a, Eq a, Monoid b) => a -> b -> b
a &&& b | a == mempty = mempty
| otherwise = b
In particular I also like this one (however I would like another name):
mapNonEmpty :: (Eq a, Monoid a, Monoid b) => (a -> b) -> a -> b
mapNonEmpty f x | x == mempty = mempty
| otherwise = f x
More information about the Haskell-Cafe