From 03e820659c93758f0eb7b40d461f3fea1dfce1af Mon Sep 17 00:00:00 2001 From: Arnaud Spiwack Date: Thu, 28 Apr 2022 11:46:38 +0200 Subject: [PATCH] Add a ($^) application function which moves the argument Closes #406 --- src/Data/Unrestricted/Linear.hs | 8 ++++---- src/Data/Unrestricted/Linear/Internal/Movable.hs | 11 +++++++++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/Data/Unrestricted/Linear.hs b/src/Data/Unrestricted/Linear.hs index ad7d88f8..f0a91f28 100644 --- a/src/Data/Unrestricted/Linear.hs +++ b/src/Data/Unrestricted/Linear.hs @@ -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 diff --git a/src/Data/Unrestricted/Linear/Internal/Movable.hs b/src/Data/Unrestricted/Linear/Internal/Movable.hs index 0a8fbc52..830b2df8 100644 --- a/src/Data/Unrestricted/Linear/Internal/Movable.hs +++ b/src/Data/Unrestricted/Linear/Internal/Movable.hs @@ -4,8 +4,10 @@ {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} +{-# LANGUAGE KindSignatures #-} {-# LANGUAGE LambdaCase #-} {-# LANGUAGE LinearTypes #-} +{-# LANGUAGE PolyKinds #-} {-# LANGUAGE QuantifiedConstraints #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE StandaloneDeriving #-} @@ -18,6 +20,7 @@ module Data.Unrestricted.Linear.Internal.Movable ( -- * Movable Movable (..), + ($^), GMovable, genericMove, ) @@ -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 @@ -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