Skip to content

Instantly share code, notes, and snippets.

@sgraf812
Created November 8, 2019 13:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sgraf812/d2a47037fc152c18b4d191568db8b1ae to your computer and use it in GitHub Desktop.
Save sgraf812/d2a47037fc152c18b4d191568db8b1ae to your computer and use it in GitHub Desktop.
etaReaderT
module Tmp where
import Control.Monad.Reader
import GHC.Exts
r :: Int -> Reader Int Int
r x = case sum [0..x] of n -> (+ n) <$> ask
etaReaderT :: Reader r a -> Reader r a
etaReaderT = ReaderT . oneShot . runReaderT
r2 :: Int -> Reader Int Int
r2 x = etaReaderT (case sum [0..x] of n -> (+ n) <$> ask)
[1 of 1] Compiling Tmp ( Tmp.hs, Tmp.o )
==================== Tidy Core ====================
Result size of Tidy Core
= {terms: 117, types: 83, coercions: 44, joins: 3/4}
-- RHS size: {terms: 6, types: 9, coercions: 4, joins: 0/0}
Tmp.etaReaderT1
:: forall a r.
ReaderT r Data.Functor.Identity.Identity a
-> r -> Data.Functor.Identity.Identity a
[GblId,
Arity=2,
Caf=NoCafRefs,
Str=<C(S),1*C1(U)><L,U>,
Unf=Unf{Src=InlineStable, TopLvl=True, Value=True, ConLike=True,
WorkFree=True, Expandable=True,
Guidance=ALWAYS_IF(arity=2,unsat_ok=True,boring_ok=True)
Tmpl= \ (@ a_a3na)
(@ r4_a3n9)
(x_X3AY [Occ=Once]
:: ReaderT r4_a3n9 Data.Functor.Identity.Identity a_a3na)
(v_B2 [Occ=Once, OS=OneShot] :: r4_a3n9) ->
(x_X3AY
`cast` (Control.Monad.Trans.Reader.N:ReaderT[0]
<r4_a3n9>_R <Data.Functor.Identity.Identity>_R <a_a3na>_N
:: ReaderT r4_a3n9 Data.Functor.Identity.Identity a_a3na
~R# (r4_a3n9 -> Data.Functor.Identity.Identity a_a3na)))
v_B2}]
Tmp.etaReaderT1
= \ (@ a_a3na)
(@ r4_a3n9)
(x_X3AY :: ReaderT r4_a3n9 Data.Functor.Identity.Identity a_a3na)
(v_B2 [OS=OneShot] :: r4_a3n9) ->
(x_X3AY
`cast` (Control.Monad.Trans.Reader.N:ReaderT[0]
<r4_a3n9>_R <Data.Functor.Identity.Identity>_R <a_a3na>_N
:: ReaderT r4_a3n9 Data.Functor.Identity.Identity a_a3na
~R# (r4_a3n9 -> Data.Functor.Identity.Identity a_a3na)))
v_B2
-- RHS size: {terms: 3, types: 6, coercions: 16, joins: 0/0}
etaReaderT :: forall r a. Reader r a -> Reader r a
[GblId,
Arity=2,
Caf=NoCafRefs,
Str=<C(S),1*C1(U)><L,U>,
Unf=Unf{Src=InlineStable, TopLvl=True, Value=True, ConLike=True,
WorkFree=True, Expandable=True,
Guidance=ALWAYS_IF(arity=0,unsat_ok=True,boring_ok=True)
Tmpl= (\ (@ r4_a3n9) (@ a_a3na) ->
Tmp.etaReaderT1 @ a_a3na @ r4_a3n9)
`cast` (forall (r4 :: <*>_N) (a :: <*>_N).
<ReaderT r4 Data.Functor.Identity.Identity a>_R
->_R Sym (Control.Monad.Trans.Reader.N:ReaderT[0]
<r4>_R <Data.Functor.Identity.Identity>_R <a>_N)
:: (forall r4 a.
ReaderT r4 Data.Functor.Identity.Identity a
-> r4 -> Data.Functor.Identity.Identity a)
~R# (forall r4 a.
ReaderT r4 Data.Functor.Identity.Identity a
-> ReaderT r4 Data.Functor.Identity.Identity a))}]
etaReaderT
= (\ (@ r4_a3n9) (@ a_a3na) -> Tmp.etaReaderT1 @ a_a3na @ r4_a3n9)
`cast` (forall (r4 :: <*>_N) (a :: <*>_N).
<ReaderT r4 Data.Functor.Identity.Identity a>_R
->_R Sym (Control.Monad.Trans.Reader.N:ReaderT[0]
<r4>_R <Data.Functor.Identity.Identity>_R <a>_N)
:: (forall r4 a.
ReaderT r4 Data.Functor.Identity.Identity a
-> r4 -> Data.Functor.Identity.Identity a)
~R# (forall r4 a.
ReaderT r4 Data.Functor.Identity.Identity a
-> ReaderT r4 Data.Functor.Identity.Identity a))
-- RHS size: {terms: 1, types: 0, coercions: 0, joins: 0/0}
Tmp.$trModule4 :: Addr#
[GblId,
Caf=NoCafRefs,
Unf=Unf{Src=<vanilla>, TopLvl=True, Value=True, ConLike=True,
WorkFree=True, Expandable=True, Guidance=IF_ARGS [] 20 0}]
Tmp.$trModule4 = "main"#
-- RHS size: {terms: 2, types: 0, coercions: 0, joins: 0/0}
Tmp.$trModule3 :: GHC.Types.TrName
[GblId,
Caf=NoCafRefs,
Str=m1,
Unf=Unf{Src=<vanilla>, TopLvl=True, Value=True, ConLike=True,
WorkFree=True, Expandable=True, Guidance=IF_ARGS [] 10 20}]
Tmp.$trModule3 = GHC.Types.TrNameS Tmp.$trModule4
-- RHS size: {terms: 1, types: 0, coercions: 0, joins: 0/0}
Tmp.$trModule2 :: Addr#
[GblId,
Caf=NoCafRefs,
Unf=Unf{Src=<vanilla>, TopLvl=True, Value=True, ConLike=True,
WorkFree=True, Expandable=True, Guidance=IF_ARGS [] 20 0}]
Tmp.$trModule2 = "Tmp"#
-- RHS size: {terms: 2, types: 0, coercions: 0, joins: 0/0}
Tmp.$trModule1 :: GHC.Types.TrName
[GblId,
Caf=NoCafRefs,
Str=m1,
Unf=Unf{Src=<vanilla>, TopLvl=True, Value=True, ConLike=True,
WorkFree=True, Expandable=True, Guidance=IF_ARGS [] 10 20}]
Tmp.$trModule1 = GHC.Types.TrNameS Tmp.$trModule2
-- RHS size: {terms: 3, types: 0, coercions: 0, joins: 0/0}
Tmp.$trModule :: GHC.Types.Module
[GblId,
Caf=NoCafRefs,
Str=m,
Unf=Unf{Src=<vanilla>, TopLvl=True, Value=True, ConLike=True,
WorkFree=True, Expandable=True, Guidance=IF_ARGS [] 10 30}]
Tmp.$trModule = GHC.Types.Module Tmp.$trModule3 Tmp.$trModule1
-- RHS size: {terms: 46, types: 18, coercions: 0, joins: 2/2}
Tmp.r3 [InlPrag=NOUSERINLINE[2]] :: Int -> Int -> Int
[GblId,
Arity=2,
Caf=NoCafRefs,
Str=<S(S),1*U(U)><S,1*U(U)>m,
Unf=Unf{Src=InlineStable, TopLvl=True, Value=True, ConLike=True,
WorkFree=True, Expandable=True,
Guidance=ALWAYS_IF(arity=2,unsat_ok=True,boring_ok=False)
Tmpl= \ (w_s4NL [Occ=Once!] :: Int) (w1_s4NM [Occ=Once!] :: Int) ->
case w_s4NL of { I# ww1_s4NP ->
case w1_s4NM of { I# ww3_s4NT [Occ=OnceL*] ->
case ># 0# ww1_s4NP of {
__DEFAULT ->
joinrec {
$wgo_s4NK [InlPrag=NOUSERINLINE[2], Occ=LoopBreakerT[2]]
:: Int# -> Int# -> Int
[LclId[JoinId(2)], Arity=2, Str=<S,U><S,U>m, Unf=OtherCon []]
$wgo_s4NK (w2_s4NE :: Int#) (ww4_s4NI [Occ=Once*] :: Int#)
= case ==# w2_s4NE ww1_s4NP of {
__DEFAULT -> jump $wgo_s4NK (+# w2_s4NE 1#) (+# ww4_s4NI w2_s4NE);
1# -> GHC.Types.I# (+# ww3_s4NT (+# ww4_s4NI w2_s4NE))
}; } in
jump $wgo_s4NK 0# 0#;
1# -> GHC.Types.I# ww3_s4NT
}
}
}}]
Tmp.r3
= \ (w_s4NL :: Int) (w1_s4NM :: Int) ->
case w_s4NL of { I# ww1_s4NP ->
case w1_s4NM of ww2_s4NS { I# ww3_s4NT ->
case ># 0# ww1_s4NP of {
__DEFAULT ->
join {
exit_Xo [Dmd=<C(C(S)),C(C1(U(U)))>] :: Int# -> Int# -> Int
[LclId[JoinId(2)], Arity=2, Str=<S,U><S,U>m]
exit_Xo (w2_s4NE [OS=OneShot] :: Int#)
(ww4_s4NI [OS=OneShot] :: Int#)
= GHC.Types.I# (+# ww3_s4NT (+# ww4_s4NI w2_s4NE)) } in
joinrec {
$wgo_s4NK [InlPrag=NOUSERINLINE[2], Occ=LoopBreaker]
:: Int# -> Int# -> Int
[LclId[JoinId(2)], Arity=2, Str=<S,U><S,U>m, Unf=OtherCon []]
$wgo_s4NK (w2_s4NE :: Int#) (ww4_s4NI :: Int#)
= case ==# w2_s4NE ww1_s4NP of {
__DEFAULT -> jump $wgo_s4NK (+# w2_s4NE 1#) (+# ww4_s4NI w2_s4NE);
1# -> jump exit_Xo w2_s4NE ww4_s4NI
}; } in
jump $wgo_s4NK 0# 0#;
1# -> ww2_s4NS
}
}
}
-- RHS size: {terms: 1, types: 0, coercions: 13, joins: 0/0}
r2 :: Int -> Reader Int Int
[GblId,
Arity=2,
Caf=NoCafRefs,
Str=<S(S),1*U(U)><S,1*U(U)>m,
Unf=Unf{Src=InlineStable, TopLvl=True, Value=True, ConLike=True,
WorkFree=True, Expandable=True,
Guidance=ALWAYS_IF(arity=0,unsat_ok=True,boring_ok=True)
Tmpl= Tmp.r3
`cast` (<Int>_R
->_R (<Int>_R
->_R Sym (Data.Functor.Identity.N:Identity[0]
<Int>_R)) ; Sym (Control.Monad.Trans.Reader.N:ReaderT[0]
<Int>_R
<Data.Functor.Identity.Identity>_R
<Int>_N)
:: (Int -> Int -> Int)
~R# (Int -> ReaderT Int Data.Functor.Identity.Identity Int))}]
r2
= Tmp.r3
`cast` (<Int>_R
->_R (<Int>_R
->_R Sym (Data.Functor.Identity.N:Identity[0]
<Int>_R)) ; Sym (Control.Monad.Trans.Reader.N:ReaderT[0]
<Int>_R
<Data.Functor.Identity.Identity>_R
<Int>_N)
:: (Int -> Int -> Int)
~R# (Int -> ReaderT Int Data.Functor.Identity.Identity Int))
-- RHS size: {terms: 2, types: 0, coercions: 0, joins: 0/0}
Tmp.r1 :: Int
[GblId,
Caf=NoCafRefs,
Str=m,
Unf=Unf{Src=<vanilla>, TopLvl=True, Value=True, ConLike=True,
WorkFree=True, Expandable=True, Guidance=IF_ARGS [] 10 20}]
Tmp.r1 = GHC.Types.I# 0#
-- RHS size: {terms: 39, types: 12, coercions: 11, joins: 1/2}
r :: Int -> Reader Int Int
[GblId,
Arity=1,
Caf=NoCafRefs,
Str=<L,1*U(U)>,
Unf=Unf{Src=<vanilla>, TopLvl=True, Value=True, ConLike=True,
WorkFree=True, Expandable=True, Guidance=IF_ARGS [20] 127 60}]
r = \ (x_a2IB :: Int) ->
let {
ds_s4LY [Dmd=<L,U(U)>] :: Int
[LclId]
ds_s4LY
= case x_a2IB of { I# y_a4Ks ->
case ># 0# y_a4Ks of {
__DEFAULT ->
joinrec {
$wgo_s4O5 [InlPrag=NOUSERINLINE[2], Occ=LoopBreaker]
:: Int# -> Int# -> Int
[LclId[JoinId(2)], Arity=2, Str=<S,U><S,U>m, Unf=OtherCon []]
$wgo_s4O5 (w_s4NZ :: Int#) (ww_s4O3 :: Int#)
= case ==# w_s4NZ y_a4Ks of {
__DEFAULT -> jump $wgo_s4O5 (+# w_s4NZ 1#) (+# ww_s4O3 w_s4NZ);
1# -> GHC.Types.I# (+# ww_s4O3 w_s4NZ)
}; } in
jump $wgo_s4O5 0# 0#;
1# -> Tmp.r1
}
} } in
(\ (x1_a3CJ :: Int) -> GHC.Num.$fNumInt_$c+ x1_a3CJ ds_s4LY)
`cast` ((<Int>_R
->_R Sym (Data.Functor.Identity.N:Identity[0]
<Int>_R)) ; Sym (Control.Monad.Trans.Reader.N:ReaderT[0]
<Int>_R
<Data.Functor.Identity.Identity>_R
<Int>_N)
:: (Int -> Int) ~R# ReaderT Int Data.Functor.Identity.Identity Int)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment