[Haskell] (.) . (.)
brianh at metamilk.com
Sun May 28 17:02:52 EDT 2006
Lennart Augustsson wrote:
> Why not ask the computer?
> -- Lennart
> bamse% ghci
> ___ ___ _
> / _ \ /\ /\/ __(_)
> / /_\// /_/ / / | | GHC Interactive, version 6.4.1, for
> Haskell 98. / /_\\/ __ / /___| | http://www.haskell.org/ghc/
> \____/\/ /_/\____/|_| Type :? for help.
> Loading package base-1.0 ... linking ... done.
> Prelude> :t (.) . (.)
> (.) . (.) :: (b -> c) -> (a -> a1 -> b) -> a -> a1 -> c
> Prelude> Leaving GHCi.
> bamse% djinn
> Welcome to Djinn version 2005-12-12.
> Type :h to get help.
> Djinn> f ? (b -> c) -> (a -> a1 -> b) -> a -> a1 -> c
> f :: (b -> c) -> (a -> a1 -> b) -> a -> a1 -> c
> f x1 x2 x3 x4 = x1 (x2 x3 x4)
> Djinn> :q
Thanks! Although I note that Djinn will give a representative function
corresponding to the type which is not necessarily (.) . (.), and the type
given by GHCi doesn't tell me how it got there...
> Brian Hulley wrote:
>> Taral wrote:
>>> On 5/28/06, Dominic Steinitz <dominic.steinitz at blueyonder.co.uk>
>>>> Is this defined in some library? Thanks, Dominic.
>>> Don't think so. I use:
>>> \a b -> f (g a b)
>> I don't see how (.) . (.) translates into something so simple.
>> Using c for (.) to make things easier to write, I get:
>> (.) . (.)
>> === c c c
>> === \x -> (c c c x)
>> === \x -> (c (c x))
>> === \x -> (\y z -> c (c x) y z)
>> === \x -> (\y z -> (c x) (y z))
>> === \x -> (\y z -> (\p q -> c x q p) (y z))
>> === \x -> (\y z -> (\p q -> x (q p) (y z))
>> === \x -> (\y z -> (\q -> x (q (y z))))
>> === \x y z q -> x (q (y z))
>> Have I made an error somewhere above?
I see my error was that I was reversing the args in eta expansion, so the
correct derivation is:
(.) . (.)
=== c c c
=== \x -> c c c x
=== \x -> c (c x)
=== \x -> (\y z -> c (c x) y z)
=== \x -> (\y z -> (c x) (y z))
=== \x -> (\y z -> (\p q -> c x p q)(y z)) -- where I went wrong before
=== \x -> (\y z -> (\p q -> x (p q))(y z))
=== \x -> (\y z -> (\q -> x ((y z) q))
=== \x y z q -> x (y z q)
My apologies to Taral for doubting the original simplification...
Logic empowers us and Love gives us purpose.
But societal laws, and religious dogma,
empower the dead,
to destroy us.
More information about the Haskell