-
-
Save treeowl/dc4dbea63b6f5e887eed64f9a89b0e32 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- This must be compiled with `-O2` or with `-O -fspec-constr` to | |
-- clean up the `Maybe`s. | |
{-# OPTIONS_GHC -O -fspec-constr #-} | |
module Dedup where | |
{-# INLINABLE f #-} | |
f :: Eq a => [a] -> [a] | |
f xs = foldr go stop xs Nothing | |
where | |
stop _ = [] | |
go x r (Just old) | |
| x == old = r (Just old) | |
go x r _ = x : r (Just x) | |
potato :: [Int] -> [Int] | |
potato = f . map (\x -> x * x) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- The below is trimmed a bit; the unfoldings aren't that exciting. | |
f [InlPrag=INLINABLE] :: forall a. Eq a => [a] -> [a] | |
f = \ (@a_a1yW) ($dEq_a1yX :: Eq a_a1yW) (xs_a1eP :: [a_a1yW]) -> | |
letrec { | |
$sgo1_s1Jj [Occ=LoopBreaker] :: a_a1yW -> [a_a1yW] -> [a_a1yW] | |
[LclId, Arity=2, Str=<L,U><S,1*U>, Unf=OtherCon []] | |
$sgo1_s1Jj | |
= \ (sc_s1Ji :: a_a1yW) (sc1_s1Jh :: [a_a1yW]) -> | |
case sc1_s1Jh of { | |
[] -> GHC.Types.[] @a_a1yW; | |
: y_a1DK ys_a1DL -> | |
case == @a_a1yW $dEq_a1yX y_a1DK sc_s1Ji of { | |
False -> GHC.Types.: @a_a1yW y_a1DK ($sgo1_s1Jj y_a1DK ys_a1DL); | |
True -> $sgo1_s1Jj sc_s1Ji ys_a1DL | |
} | |
}; } in | |
case xs_a1eP of { | |
[] -> GHC.Types.[] @a_a1yW; | |
: y_a1DK ys_a1DL -> | |
GHC.Types.: @a_a1yW y_a1DK ($sgo1_s1Jj y_a1DK ys_a1DL) | |
} | |
Rec { | |
-- RHS size: {terms: 29, types: 14, coercions: 0, joins: 0/1} | |
Dedup.potato_$sgo1 [Occ=LoopBreaker] | |
:: GHC.Prim.Int# -> [Int] -> [Int] | |
[GblId, Arity=2, Str=<L,U><S,1*U>, Unf=OtherCon []] | |
Dedup.potato_$sgo1 | |
= \ (sc_s1J7 :: GHC.Prim.Int#) (sc1_s1J6 :: [Int]) -> | |
case sc1_s1J6 of { | |
[] -> GHC.Types.[] @Int; | |
: y_a1DK ys_a1DL -> | |
case y_a1DK of { GHC.Types.I# x_a1F3 -> | |
let { | |
x1_a1GE :: GHC.Prim.Int# | |
[LclId] | |
x1_a1GE = GHC.Prim.*# x_a1F3 x_a1F3 } in | |
case GHC.Prim.==# x1_a1GE sc_s1J7 of { | |
__DEFAULT -> | |
GHC.Types.: | |
@Int (GHC.Types.I# x1_a1GE) (Dedup.potato_$sgo1 x1_a1GE ys_a1DL); | |
1# -> Dedup.potato_$sgo1 sc_s1J7 ys_a1DL | |
} | |
} | |
} | |
end Rec } | |
potato :: [Int] -> [Int] | |
[GblId, | |
Arity=1, | |
Str=<S,1*U>, | |
Unf=Unf{Src=<vanilla>, TopLvl=True, Value=True, ConLike=True, | |
WorkFree=True, Expandable=True, Guidance=IF_ARGS [30] 203 20}] | |
potato | |
= \ (x_a1BJ :: [Int]) -> | |
case x_a1BJ of { | |
[] -> GHC.Types.[] @Int; | |
: y_a1DK ys_a1DL -> | |
let { | |
x1_a1eS [Dmd=<L,U(U)>] :: Int | |
[LclId] | |
x1_a1eS | |
= case y_a1DK of { GHC.Types.I# x2_a1F3 -> | |
GHC.Types.I# (GHC.Prim.*# x2_a1F3 x2_a1F3) | |
} } in | |
GHC.Types.: | |
@Int | |
x1_a1eS | |
(case ys_a1DL of { | |
[] -> GHC.Types.[] @Int; | |
: y1_X2 ys1_X3 -> | |
case y1_X2 of { GHC.Types.I# x2_a1F3 -> | |
let { | |
x3_a1GE :: GHC.Prim.Int# | |
[LclId] | |
x3_a1GE = GHC.Prim.*# x2_a1F3 x2_a1F3 } in | |
case x1_a1eS of { GHC.Types.I# y2_a1GH -> | |
case GHC.Prim.==# x3_a1GE y2_a1GH of { | |
__DEFAULT -> | |
GHC.Types.: | |
@Int (GHC.Types.I# x3_a1GE) (Dedup.potato_$sgo1 x3_a1GE ys1_X3); | |
1# -> Dedup.potato_$sgo1 y2_a1GH ys1_X3 | |
} | |
} | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment