Skip to content

Commit

Permalink
Add a ($^) application function which moves the argument
Browse files Browse the repository at this point in the history
Closes #406
  • Loading branch information
aspiwack committed Apr 28, 2022
1 parent 113a758 commit 0b5e768
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/Data/Unrestricted/Linear/Internal/Movable.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE LinearTypes #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE QuantifiedConstraints #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
Expand All @@ -18,6 +20,7 @@
module Data.Unrestricted.Linear.Internal.Movable
( -- * Movable
Movable (..),
($^),
GMovable,
genericMove,
)
Expand All @@ -30,12 +33,11 @@ import qualified Data.Semigroup as Semigroup
import Data.Unrestricted.Linear.Internal.Dupable
import Data.Unrestricted.Linear.Internal.Ur
import GHC.Tuple (Solo)
import GHC.Types (Multiplicity (..))
import GHC.Types
import Generics.Linear
import Prelude.Linear.Generically
import Prelude.Linear.Internal
import qualified Unsafe.Linear as Unsafe
import Prelude (Bool (..), Char, Double, Float, Int, Ordering (..), Word)
import qualified Prelude as Prelude

-- | Use @'Movable' a@ to represent a type which can be used many times even
Expand All @@ -56,6 +58,11 @@ import qualified Prelude as Prelude
class Dupable a => Movable a where
move :: a %1 -> Ur a

($^) :: forall {rep} a (b :: TYPE rep). Movable a => (a -> b) %1 -> a %1 -> b
f $^ a =
move a & \case
Ur a' -> f a'

-- -------------
-- Instances

Expand Down

0 comments on commit 0b5e768

Please sign in to comment.