module Ribosome.Host.Interpreter.Id where

import Conc (interpretAtomic)
import Polysemy.Input (Input (Input))

-- |Interpret 'Input' by incrementing a numeric type starting from @1@.
interpretInputNum ::
   a r .
  Num a =>
  Member (Embed IO) r =>
  InterpreterFor (Input a) r
interpretInputNum :: forall a (r :: EffectRow).
(Num a, Member (Embed IO) r) =>
InterpreterFor (Input a) r
interpretInputNum =
  forall a (r :: EffectRow).
Member (Embed IO) r =>
a -> InterpreterFor (AtomicState a) r
interpretAtomic @a a
1 (Sem (AtomicState a : r) a -> Sem r a)
-> (Sem (Input a : r) a -> Sem (AtomicState a : r) a)
-> Sem (Input a : r) a
-> Sem r a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
  (forall (rInitial :: EffectRow) x.
 Input a (Sem rInitial) x -> Sem (AtomicState a : r) x)
-> Sem (Input a : r) a -> Sem (AtomicState a : r) a
forall (e1 :: (* -> *) -> * -> *) (e2 :: (* -> *) -> * -> *)
       (r :: EffectRow) a.
FirstOrder e1 "reinterpret" =>
(forall (rInitial :: EffectRow) x.
 e1 (Sem rInitial) x -> Sem (e2 : r) x)
-> Sem (e1 : r) a -> Sem (e2 : r) a
reinterpret \ Input a (Sem rInitial) x
Input ->
    (x -> (x, x)) -> Sem (AtomicState a : r) x
forall s a (r :: EffectRow).
Member (AtomicState s) r =>
(s -> (s, a)) -> Sem r a
atomicState' \ x
i -> (x
i x -> x -> x
forall a. Num a => a -> a -> a
+ x
1, x
i)