# How Cool is Rulz!

**URL:** <https://discourse.haskell.org/t/how-cool-is-rulz/7738>\
**Category:** Learn\
**Created:** [October 1, 2023, 2:52am UTC](https://discourse.haskell.org/t/how-cool-is-rulz/7738 "2023-10-01T02:52:14Z")\
**Posts on this page:** 1\
**Showing post:** 9

<div class="post-metadata">

**Author:** ![jaror](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/jaror/32/3271_2.png) [@jaror](https://discourse.haskell.org/u/jaror)\
**Post date:** [October 27, 2023, 6:55pm UTC](https://discourse.haskell.org/t/how-cool-is-rulz/7738/9 "2023-10-27T18:55:34Z")

</div>

I think I can tell what’s going on, but I don’t know why this happens. In the Core I found this dictionary for `Num (Posit es)`:

```haskell
Posit.$fNumPosit
  = \ (@(es :: ES)) ($dPositC :: PositC es) ->
      GHC.Num.C:Num
        @(Posit es)
        (Posit.$fNumPosit_$c+ @es $dPositC)
        (Posit.$fNumPosit_$c- @es $dPositC)
        (Posit.$fNumPosit_$c* @es $dPositC)
        (positNEG @es $dPositC)
        (positABS @es $dPositC)
        (positSIGNUM @es $dPositC)
        (Posit.$fNumPosit_$cfromInteger @es $dPositC)

```

I expected to see `positADD` there instead of `Posit.$fNumPosit_$c+`. For some reason GHC creates an intermediate function here that seems to do nothing interesting:

```haskell
-- RHS size: {terms: 4, types: 4, coercions: 0, joins: 0/0}
Posit.$fNumPosit_$c+ [Occ=LoopBreaker]
  :: forall (es :: ES). PositC es => Posit es -> Posit es -> Posit es
[GblId,
 Arity=3,
 Str=<SP(L,L,SC(S,L),L,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L)><1P(A,1L)><MP(A,L)>,
 Cpr=1,
 Unf=OtherCon []]
Posit.$fNumPosit_$c+
  = \ (@(es :: ES)) ($dPositC :: PositC es) -> positADD @es $dPositC
end Rec }

```

The rewrite rule won’t apply if this function is used instead of `positADD` directly.

@sgraf is probably better equipped to explain why this happens.

Here’s the Core of `positADD`:

```haskell
-- RHS size: {terms: 11, types: 14, coercions: 0, joins: 0/0}
positADD [InlPrag=NOINLINE[final]]
  :: forall (es :: ES). PositC es => Posit es -> Posit es -> Posit es
[GblId,
 Arity=3,
 Str=<SP(L,L,SC(S,L),L,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L)><1P(A,1L)><MP(A,L)>,
 Cpr=1,
 Unf=Unf{Src=StableSystem, TopLvl=True,
         Value=True, ConLike=True, WorkFree=True, Expandable=True,
         Guidance=ALWAYS_IF(arity=3,unsat_ok=True,boring_ok=False)
         Tmpl= \ (@(es :: ES))
                 ($dPositC [Occ=Once1] :: PositC es)
                 (x [Occ=Once1!] :: Posit es)
                 (y [Occ=Once1] :: Posit es) ->
                 case x of { Posit _ [Occ=Dead] ww1 [Occ=Once1] ->
                 Posit.$wpositADD @es $dPositC ww1 y
                 }}]
positADD
  = \ (@(es :: ES))
      ($dPositC :: PositC es)
      (x :: Posit es)
      (y :: Posit es) ->
      case x of { Posit ww ww1 -> Posit.$wpositADD @es $dPositC ww1 y }

```

---

_[View the full topic](https://discourse.haskell.org/t/how-cool-is-rulz/7738)._
