[Haskell-beginners] small expression evaluator
Henk-Jan van Tuyl
hjgtuyl at chello.nl
Tue Mar 22 13:43:51 CET 2011
On Tue, 22 Mar 2011 10:14:57 +0100, Henk-Jan van Tuyl <hjgtuyl at chello.nl>
wrote:
> On Tue, 22 Mar 2011 08:56:45 +0100, Petr Novotnik
> <pnovotnik at googlemail.com> wrote:
>
>> data Person = Person {
>> personName :: String
>> , personAge :: Int
>> }
>> deriving (Show)
>>
>> exampleExpr :: Bool
>> exampleExpr = (VConst 99) .==. (VFunc personAge) $ Person "pete" 99
>>
>>
>> I was wondering, whether it'd be possible to enable defining expression
>> without the Value data constructors, i.e.
>>
>>
>> 99 .==. personAge $ Person "pete" 99
>
> You can write:
> 99 == personAge (Person "pete" 99)
>
Or you could write:
c .==. f = \x -> c == f x
test = 99 .==. personAge $ Person "pete" 99
The .==. operator is not symmetrical in this case, of course
Regards,
Henk-Jan van Tuyl
--
http://Van.Tuyl.eu/
http://members.chello.nl/hjgtuyl/tourdemonad.html
--
More information about the Beginners
mailing list