[Haskell-cafe] Operator overloading
Brent Yorgey
byorgey at gmail.com
Thu Aug 9 14:32:54 EDT 2007
On 8/9/07, rodrigo.bonifacio <rodrigo.bonifacio at uol.com.br> wrote:
>
> Hi all.
>
> I want to overload the operator "^" for working instead of the following
> "+++" operator:
>
> (+++) :: String -> [[String]] -> [[String]]
> x +++ y = [ x:e | e<-y ]
>
> How can I overload the "^" operator?
import Prelude hiding ( (^) ) -- this is the key
(^) :: String -> [[String]] -> [[String]]
x ^ y = [ x:e | e<-y ]
By the way, there's nothing special about Strings here: if you made the type
of ^
(^) :: a -> [[a]] -> [[a]]
it would work on lists of any type, including String.
-Brent
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20070809/1e178ede/attachment.htm
More information about the Haskell-Cafe
mailing list