Re:Ladies, look at your code. Now back to mine.
by jrockway on Saturday August 28, 2010 @04:42AM
(#1641482)
That's what's nice about functional programming, where functions are functions, not thingies inside your object. You would write something like:
Where . is function composition.
[ Parent
| on HN ]
Re:Ladies, look at your code. Now back to mine.
by jlouis on Saturday August 28, 2010 @06:06AM
(#1641547)
You still need to hope the fusion optimization kicks in there. It can be done faster with one filter over the list and then checking all three predicates at each element in some cases. I think the following will do the right thing:
filter (\x -> p1 x && p2 x && p3 x) employees
which can then be made points-free.
Re:Ladies, look at your code. Now back to mine.
by lsb on Saturday August 28, 2010 @10:22AM
(#1641765)
Don't just hope, write it yourself!
{-# RULES
"filter/filter" forall f g xs. filter f (filter g xs) = filter (f.g) xs
#-}
It's a programmable programming language.
Re:Ladies, look at your code. Now back to mine.
by uros643 on Saturday August 28, 2010 @08:25PM
(#1642740)
Don't you mean
forall f g xs. map f (map g xs) = map (f.g) xs
?As for filter, I presume something like
forall f g xs. filter f (filter g xs) = filter (\x. g x && f x) xs
would work.
Re:Ladies, look at your code. Now back to mine.
by lsb on Sunday August 29, 2010 @09:46AM
(#1643790)
Yup,
forall f g xs . filter f (filter g xs) = filter (\x -> g x && f x) xs
was exactly what I meant, thanks for the catch!
Re:Ladies, look at your code. Now back to mine.
by ced on Saturday August 28, 2010 @10:33AM
(#1641775)
Nice. What's the limit on what you can do with these RULES? Could you extend the language? Write a DSL? Implement a mini-prolog à la On Lisp?