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 03e8206
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/Data/Unrestricted/Linear.hs
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,22 @@ module Data.Unrestricted.Linear

-- * Performing non-linear actions on linearly bound values
Consumable (..),
Dupable (..),
Movable (..),
lseq,
Dupable (..),
dup,
dup3,
dup4,
dup5,
dup6,
dup7,
module Data.Unrestricted.Linear.Internal.Instances,
Movable (..),
($^),
)
where

import Data.Unrestricted.Linear.Internal.Consumable
import Data.Unrestricted.Linear.Internal.Dupable
import Data.Unrestricted.Linear.Internal.Instances
import Data.Unrestricted.Linear.Internal.Instances ()
import Data.Unrestricted.Linear.Internal.Movable
import Data.Unrestricted.Linear.Internal.Ur
import Data.Unrestricted.Linear.Internal.UrT
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 03e8206

Please sign in to comment.