Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a ($^) application function which moves the argument #413

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
5 changes: 3 additions & 2 deletions src/Prelude/Linear.hs
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,12 @@ module Prelude.Linear
-- * Doing non-linear operations inside linear functions
-- $
Consumable (..),
Dupable (..),
Movable (..),
lseq,
Dupable (..),
dup,
dup3,
Movable (..),
($^),
forget,
)
where
Expand Down