
Yes, that’s right: simplCast is the guy. I can’t explain why it’s not working for you, though
Simon
From: conal.elliott@gmail.com [mailto:conal.elliott@gmail.com] On Behalf Of Conal Elliott
Sent: 08 May 2014 04:19
To: Simon Peyton Jones
Cc: ghc-devs@haskell.org
Subject: Re: Simplifying casts and beta-reduction
I'm still sorting through how to optimize these almost-beta-redexes in the form `((\ x -> u) |> co) v`, shifting coercions to enable beta-reduction (as described in section 3.1 of "Evidence normalization"). Is it done by `simplCast` (with help from `simplCoercion`), as called indirectly from `simplifyExpr` in `SimplCore`? I think I'm now calling `simplifyExpr` from HERMIT but I'm not getting the cast-shifting I'm looking for.
-- Conal
On Wed, May 7, 2014 at 1:02 PM, Conal Elliott
((\ (@ a8) (@ b) ($dEncodable :: Encodable a8) ($dEncodable1 :: Encodable b) -> case $dEncodable of _ D:Encodable _ tpl_B3 -> case $dEncodable1 of _ D:Encodable tpl_B2 _ -> \ (g :: a8 -> b) (eta :: Encode a8) -> tpl_B2 (g (tpl_B3 eta)) ) `cast` (forall a8 b. <Encodable a8>_R -> <Encodable b>_R ->
b>_R -> Sub (Sym (TFCo:R:Encode(->)[0] <a8>_N <b>_N)) :: (forall a8 b. (Encodable a8, Encodable b) => (a8 -> b) -> Encode a8 -> Encode b) ~# (forall a8 b. (Encodable a8, Encodable b) => (a8 -> b) -> Encode (a8 -> b))))
I can imagine pushing the `cast` down through the type lambdas while stripping off `forall` coercions, then pushing the remaining `cast` through the dictionary arguments, while stripping off the outer `<Encodable t>_R ->` coercion wrappers, and then pushing the cast into the `case` alternatives and the lambda body, leaving something like
(\ (@ a8) (@ b) ($dEncodable :: Encodable a8) ($dEncodable1 :: Encodable b) -> case $dEncodable of _ D:Encodable _ tpl_B3 -> case $dEncodable1 of _ D:Encodable tpl_B2 _ -> \ (g :: a8 -> b) -> (\ (eta :: Encode a8) -> tpl_B2 (g (tpl_B3 eta))) `cast` (Sub (Sym (TFCo:R:Encode(->)[0] <a8>_N <b>_N)) :: (Encode a8 -> Encode b) ~# (Encode (a8 -> b))))
Now, given type, dictionary, and function arguments, I think we could beta-reduce. Before I try implementing these transformations, does something like them already exist in GHC? Thanks, -- Conal