Drop DA.Next.Set and DA.Next.Map (#11864)

* Drop DA.Next.Set and DA.Next.Map

Fixes #11527. Also removed a bunch of unnecessary CPP, though there's
still a lot more CPP to remove.

changelog_begin

- [Daml Standard Library] DA.Next.Map and DA.Next.Set have been removed
  after being deprecated since Daml-LF 1.11

changelog_end

* Drop a deriving MapKey

* update unstable-types test
This commit is contained in:
Sofia Faro 2021-11-25 13:02:08 +00:00 committed by GitHub
parent 5f3a4d2067
commit 2f8f69e7cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 17 additions and 637 deletions

View File

@ -21,9 +21,7 @@ module DA.Internal.LF
, TextMap
#ifdef DAML_GENMAP
, Map
#endif
, Update
@ -125,26 +123,24 @@ instance Ord Time where (<=) = primitive @"BELessEq"
data TextMap a =
TextMap Opaque
#ifdef DAML_GENMAP
-- | The `Map a b` type represents an associative array from keys of type `a`
-- to values of type `b`. It uses the built-in equality for keys. Import
-- `DA.Map` to use it.
data Map a b =
Map Opaque
#endif
-- | The `ContractId a` type represents an ID for a contract created from a template `a`.
-- You can use the ID to fetch the contract, among other things.
data ContractId a =
ContractId Opaque
instance Eq (ContractId a) where (==) = primitive @"BEEqualContractId"
#ifdef DAML_GENERIC_COMPARISON
instance Ord (ContractId a) where
(<) = primitive @"BELess"
(<=) = primitive @"BELessEq"
(>) = primitive @"BEGreater"
(>=) = primitive @"BEGreaterEq"
#endif
instance Show (ContractId a) where
#ifdef DAML_CONTRACT_ID_TO_TEXT
show cid = case primitive @"BEContractIdToText" cid of
@ -267,13 +263,11 @@ data TypeRep = TypeRep Opaque
instance Eq TypeRep where
(==) = primitive @"BEEqual"
#ifdef DAML_GENERIC_COMPARISON
instance Ord TypeRep where
(<=) = primitive @"BELessEq"
(>=) = primitive @"BEGreaterEq"
(<) = primitive @"BELess"
(>) = primitive @"BEGreater"
#endif -- DAML_GENERIC_COMPARISON
#endif
#ifdef DAML_EXCEPTIONS

View File

@ -2,7 +2,6 @@
-- SPDX-License-Identifier: Apache-2.0
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE ScopedTypeVariables #-}
@ -13,16 +12,12 @@
-- | MOVE Prelude Daml-LF primitives, just templates/contracts
module DA.Internal.Template.Functions where
#ifdef DAML_ANY_TYPE
import DA.Internal.Any
#endif
import DA.Internal.LF
import DA.Internal.Prelude
import DA.Internal.Template
#ifdef DAML_GENMAP && DAML_ANY_TYPE
import GHC.Types (primitive)
#endif
type TemplateOrInterface t =
( HasTemplateTypeRep t
@ -227,28 +222,19 @@ instance IsParties (Optional Party) where
toParties None = []
toParties (Some p) = [p]
#ifdef DAML_GENERIC_COMPARISON && DAML_ANY_TYPE
instance Eq AnyTemplate where
(==) = primitive @"BEEqual"
instance Eq AnyChoice where
(==) = primitive @"BEEqual"
instance Eq AnyContractKey where
(==) = primitive @"BEEqual"
instance Ord AnyTemplate where
(<=) = primitive @"BELessEq"
instance Ord AnyChoice where
(<=) = primitive @"BELessEq"
instance Ord AnyContractKey where
(<=) = primitive @"BELessEq"
#endif
#ifdef DAML_TYPE_REP
-- | Generate a unique textual representation of the template id.
templateTypeRep : forall t. HasTemplateTypeRep t => TemplateTypeRep
@ -257,11 +243,7 @@ templateTypeRep = TemplateTypeRep (_templateTypeRep ([] : [t]))
instance Eq TemplateTypeRep where
TemplateTypeRep a == TemplateTypeRep b = a == b
#ifdef DAML_GENERIC_COMPARISON
deriving instance Ord TemplateTypeRep
#endif
#ifdef DAML_ANY_TYPE
-- | Wrap the template in `AnyTemplate`.
--
@ -325,8 +307,6 @@ fromAnyContractKey (AnyContractKey any rep)
| Some k <- _fromAnyContractKey ([] : [t]) any
, templateTypeRep @t == rep = Some k
| otherwise = None
#endif
#endif
deriving instance Eq Archive
deriving instance Show Archive

View File

@ -1,10 +1,5 @@
-- Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
-- SPDX-License-Identifier: Apache-2.0
{-# LANGUAGE CPP #-}
#ifndef DAML_GENMAP
module DA.List.BuiltinOrder where
#else
-- | Note: This is only supported in DAML-LF 1.11 or later.
--
@ -151,4 +146,3 @@ goUniqueOn f m (x :: xs) =
in case Map.lookup (f x) m of
None -> goUniqueOn f (Map.insert k () m) xs
Some _ -> False
#endif

View File

@ -1,17 +1,6 @@
-- Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
-- SPDX-License-Identifier: Apache-2.0
{-# LANGUAGE CPP #-}
#ifndef DAML_GENMAP
-- | HIDE
module DA.Map where
#else
-- | Note: This is only supported in DAML-LF 1.11 or later.
--
-- This module exports the generic map type `Map k v` and associated
@ -240,5 +229,3 @@ instance Ord k => Foldable.Foldable (Map k) where
instance Ord k => Traversable.Traversable (Map k) where
mapA f x = fmap fromList $ mapA (\(k, v) -> fmap (k,) $ f v) $ toList x
#endif

View File

@ -1,196 +0,0 @@
-- Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
-- SPDX-License-Identifier: Apache-2.0
{-# LANGUAGE CPP #-}
#ifdef DAML_GENMAP
-- | `DA.Next.Map` is deprecated. Please use `DA.Map` instead.
module DA.Next.Map
{-# DEPRECATED "DA.Next.Map is deprecated. Please use DA.Map instead." #-}
#else
-- | Map - A `Map` is an associative array data type composed of a
-- collection of key/value pairs such that each possible key appears
-- at most once in the collection.
module DA.Next.Map
#endif
( Map
, MapKey (..)
, empty
, size
, toList
, fromList
, fromListWith
, toTextMap
, fromTextMap
, null
, lookup
, member
, filter
, filterWithKey
, delete
, insert
, union
, merge
) where
import Prelude hiding (lookup, null, filter, empty)
import DA.Foldable qualified as Foldable
import DA.Text
import DA.TextMap (TextMap)
import DA.TextMap qualified as TextMap
import DA.Traversable qualified as Traversable
import DA.Tuple
-- | A `Map k v` is an associative array data type composed of a
-- collection of key/value pairs of key type `k` and value type `v`
-- such that each possible key appears at most once in the collection.
newtype Map k v = Map with textMap : TextMap v
deriving (Eq, Ord, Foldable.Foldable)
-- | A class for types that can be used as keys for the `Map` type.
-- All keys `k` must satisfy `keyFromText (keyToText k) == k`.
class Eq k => MapKey k where
-- | Turn a key into its textual representation. This function must be
-- injective.
keyToText : k -> Text
-- | Recover a key from its textual representation. `keyFromText x` is
-- allowed to fail whenever there is _no_ key `k` with `keyToText k == x`.
-- Whenever such a `k` does exist, then it must satisfy
-- `keyFromText x == k`.
keyFromText : Text -> k
instance MapKey Text where
keyToText x = x
keyFromText x = x
keyFromTextNote : Text -> Text -> Text
keyFromTextNote target t =
"keyFromText: could not parse " <> show t <> " as '" <> target <> "'"
instance MapKey Party where
keyToText = partyToText
keyFromText t =
case partyFromText t of
None -> error (keyFromTextNote "Party" t)
Some x -> x
instance MapKey Int where
keyToText = show
keyFromText t =
case parseInt t of
None -> error (keyFromTextNote "Int" t)
Some x -> x
instance MapKey Decimal where
keyToText = show
keyFromText t =
case parseDecimal t of
None -> error (keyFromTextNote "Decimal" t)
Some x -> x
-- | Create a map from a list of key/value pairs.
fromList : MapKey k => [(k, v)] -> Map k v
fromList kvs = Map $ TextMap.fromList $ map (first keyToText) kvs
-- | Create a map from a list of key/value pairs with a combining
-- function. Examples:
-- ```
-- fromListWith (<>) [(5,"a"), (5,"b"), (3,"b"), (3,"a"), (5,"c")] == fromList [(3, "ba"), (5, "abc")]
-- fromListWith (<>) [] == (empty : Map Int Text)
-- ```
fromListWith : MapKey k => (v -> v -> v) -> [(k, v)] -> Map k v
fromListWith f kvs = Map $ TextMap.fromListWith f $ map (first keyToText) kvs
-- | Convert the map to a list of key/value pairs where the keys are
-- in ascending order of their textual representation.
toList : MapKey k => Map k v -> [(k, v)]
toList (Map t) = map (first keyFromText) $ TextMap.toList t
-- | Create a `Map` from a `TextMap`.
fromTextMap : TextMap v -> Map Text v
fromTextMap = Map
-- | Convert a `Map` into a `TextMap`.
toTextMap : MapKey k => Map k v -> TextMap v
toTextMap (Map t) = t
-- | The empty map.
empty : Map k v
empty = Map TextMap.empty
-- | Number of elements in the map.
size : Map k v -> Int
size (Map t) = TextMap.size t
-- | Is the map empty?
null : Map k v -> Bool
null m = size m == 0
-- | Lookup the value at a key in the map.
lookup : MapKey k => k -> Map k v -> Optional v
lookup k (Map t) = TextMap.lookup (keyToText k) t
-- | Is the key a member of the map?
member : MapKey k => k -> Map k v -> Bool
member k (Map t) = TextMap.member (keyToText k) t
-- | Filter the `Map` using a predicate: keep only the entries where the
-- value satisfies the predicate.
filter : MapKey k => (v -> Bool) -> Map k v -> Map k v
filter p = filterWithKey (const p)
-- | Filter the `Map` using a predicate: keep only the entries which
-- satisfy the predicate.
filterWithKey : MapKey k => (k -> v -> Bool) -> Map k v -> Map k v
filterWithKey p (Map t) = Map $ TextMap.filterWithKey (p . keyFromText) t
-- | Delete a key and its value from the map. When the key is not a
-- member of the map, the original map is returned.
delete : MapKey k => k -> Map k v -> Map k v
delete k (Map t) = Map $ TextMap.delete (keyToText k) t
-- | Insert a new key/value pair in the map. If the key is already
-- present in the map, the associated value is replaced with the
-- supplied value.
insert : MapKey k => k -> v -> Map k v -> Map k v
insert k v (Map t) = Map $ TextMap.insert (keyToText k) v t
-- | The union of two maps, preferring the first map when equal
-- keys are encountered.
union : MapKey k => Map k v -> Map k v -> Map k v
union (Map t1) (Map t2) = Map $ TextMap.union t1 t2
-- | Merge two maps. `merge f g h x y` applies `f` to all key/value pairs
-- whose key only appears in `x`, `g` to all pairs whose key only appears
-- in `y` and `h` to all pairs whose key appears in both `x` and `y`.
-- In the end, all pairs yielding `Some` are collected as the result.
merge
: MapKey k
=> (k -> a -> Optional c)
-> (k -> b -> Optional c)
-> (k -> a -> b -> Optional c)
-> Map k a
-> Map k b
-> Map k c
merge f g h (Map xs) (Map ys) = Map $ TextMap.merge (f . keyFromText) (g . keyFromText) (h . keyFromText) xs ys
instance (MapKey k, Show k, Show v) => Show (Map k v) where
show m = "Map " <> show (toList m)
deriving instance MapKey k => Semigroup (Map k v)
-- TODO(MH): The converter to Daml-LF can't handle deriving this right now.
-- It fails with "Coercion with symco."
-- deriving instance MapKey k => Monoid (Map k v)
instance MapKey k => Monoid (Map k v) where
mempty = empty
deriving instance MapKey k => Functor (Map k)
instance MapKey k => Traversable.Traversable (Map k) where
mapA f (Map t) = fmap Map $ Traversable.mapA f t

View File

@ -1,130 +0,0 @@
-- Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
-- SPDX-License-Identifier: Apache-2.0
{-# OPTIONS -Wno-deprecations #-}
{-# LANGUAGE CPP #-}
#ifdef DAML_GENMAP
-- | `DA.Next.Set` is deprecated. Please use `DA.Set` instead.
module DA.Next.Set
{-# DEPRECATED "DA.Next.Set is deprecated. Please use DA.Set instead." #-}
#else
-- | Set - The `Set a` type represents a set of elements of type
-- `a`. Most operations require that `a` be an instance of the `MapKey`
-- type class.
module DA.Next.Set
#endif
( Set
, empty
, size
, toList
, fromList
, toTextMap
, fromTextMap
, member
, null
, insert
, filter
, delete
, singleton
, union
, intersection
, difference
)
where
import Prelude hiding (filter, null, empty)
import DA.Next.Map (MapKey (..))
import DA.TextMap (TextMap)
import DA.TextMap qualified as TextMap
-- | The type of a set.
newtype Set a = Set with textMap : TextMap ()
deriving (Eq, Ord)
-- NOTE(MH): This is not a newtype wrapper around the `Map` type such that
-- people using `Set` over the Ledger API don't have to wrap every set into
-- two layers of newtypes.
-- | The empty set.
empty : Set a
empty = Set TextMap.empty
-- | The number of elements in the set.
size : Set a -> Int
size (Set t) = TextMap.size t
-- | Convert the set to a list of elements.
toList : MapKey a => Set a -> [a]
toList (Set t) = map (keyFromText . fst) $ TextMap.toList t
-- | Create a set from a list of elements.
fromList : MapKey a => [a] -> Set a
fromList xs = Set $ TextMap.fromList $ map (\x -> (keyToText x, ())) xs
-- | Convert a `Set` into a `TextMap`.
toTextMap : Set Text -> TextMap ()
toTextMap (Set t) = t
-- | Create a `Set` from a `TextMap`.
fromTextMap : TextMap () -> Set Text
fromTextMap = Set
-- | Is the element in the set?
member : MapKey a => a -> Set a -> Bool
member x (Set t) = TextMap.member (keyToText x) t
-- | Is this the empty set?
null : Set a -> Bool
null (Set t) = TextMap.null t
-- | Insert an element in a set. If the set already contains an
-- element equal to the given value, it is replaced with the new
-- value.
insert : MapKey a => a -> Set a -> Set a
insert x (Set t) = Set $ TextMap.insert (keyToText x) () t
-- | Filter all elements that satisfy the predicate.
filter : MapKey a => (a -> Bool) -> Set a -> Set a
filter p (Set t) = Set $ TextMap.filterWithKey (\x () -> p (keyFromText x)) t
-- | Delete an element from a set.
delete : MapKey a => a -> Set a -> Set a
delete x (Set t) = Set $ TextMap.delete (keyToText x) t
-- | Create a singleton set.
singleton : MapKey a => a -> Set a
singleton x = insert x empty
-- | The union of two sets, preferring the first set when equal
-- elements are encountered.
union : MapKey a => Set a -> Set a -> Set a
union (Set t1) (Set t2) = Set $ TextMap.union t1 t2
-- | The intersection of two sets. Elements of the result come from
-- the first set.
intersection : MapKey a => Set a -> Set a -> Set a
intersection s1 s2 = filter (`member` s2) s1
-- | `difference x y` returns the set consisting of all
-- elements in `x` that are not in `y`.
--
-- >>> fromList [1, 2, 3] `difference` fromList [1, 4]
-- fromList [2, 3]
difference : MapKey a => Set a -> Set a -> Set a
difference s1 s2 = filter (\x -> not (x `member` s2)) s1
instance (MapKey a, Show a) => Show (Set a) where
show s = "Set " <> show (toList s)
instance IsParties (Set Party) where
toParties = toList
instance MapKey a => Semigroup (Set a) where
(<>) = union
instance MapKey a => Monoid (Set a) where
mempty = empty

View File

@ -4,13 +4,6 @@
{-# LANGUAGE CPP #-}
{-# OPTIONS_GHC -Wno-orphans #-}
#ifndef DAML_GENMAP
-- | HIDE
module DA.Set where
#else
-- | Note: This is only supported in DAML-LF 1.11 or later.
--
-- This module exports the generic set type `Set k` and associated
@ -159,4 +152,3 @@ instance Foldable.Foldable Set where
foldMap f xs = Foldable.foldMap f (DA.Set.toList xs)
length = size
null = DA.Set.null
#endif

View File

@ -3,13 +3,6 @@
{-# LANGUAGE CPP #-}
#ifndef DAML_GENMAP
-- | HIDE
module DA.Set.Types where
#else
-- | MOVE DA.Set
module DA.Set.Types where
@ -18,5 +11,3 @@ import DA.Internal.LF (Map)
-- | The type of a set. This is a wrapper over the `Map` type.
data Set k = Set with
map : Map k ()
#endif

View File

@ -40,8 +40,6 @@ import DA.Math
import DA.Maybe.Total
import DA.Maybe
import DA.Monoid
import DA.Next.Map
import DA.Next.Set
import DA.NonEmpty
import DA.Numeric
import DA.Optional.Total

View File

@ -1,77 +0,0 @@
-- We test for deprecations in NextMapDeprecated
{-# OPTIONS -Wno-deprecations #-}
-- Copyright (c) 2020, Digital Asset (Switzerland) GmbH and/or its affiliates.
-- All rights reserved.
-- @ERROR could not parse ""notaparty"" as 'Party'
-- @ERROR could not parse "not-an-int" as 'Int'
-- @ERROR could not parse "not-a-decimal" as 'Decimal'
module NextMap where
import DA.Next.Map as M
import DA.Assert
testEmpty = scenario do
0 === size M.empty
[] === toList (M.empty : Map Int Decimal)
testSize = scenario do
0 === size (fromList ([] : [(Int, Decimal)]))
3 === size (fromList ([(1, 2.0), (2, 9.0), (3, 2.2)] : [(Int, Decimal)]))
testToList = scenario do
[(1, "c"), (2, "a"), (5, "b")] === toList (fromList [(2, "a"), (5, "b"), (1, "c")])
testFromList = scenario do
False === member 2 (fromList [(1, "a"), (3, "b"), (4, "c")])
True === member 3 (fromList [(1, "a"), (3, "b"), (4, "c")])
[(1, "b")] === toList (fromList [(1, "a"), (1, "c"), (1, "b")])
testFromListWith = scenario do
fromListWith (<>) [(5,"a"), (5,"b"), (3,"b"), (3,"a"), (5,"c")] === fromList [(3, "ba"), (5, "abc")]
fromListWith (<>) [] === (M.empty : Map Int Text)
testMember = scenario do
False === member "a" (fromList ([("", 1.0), ("b", 2.0), ("c", 3.0)] : [(Text, Decimal)]))
True === member "" (fromList ([("", 1.0), ("b", 2.0), ("c", 3.0)] : [(Text, Decimal)]))
False === member 2 (fromList [])
testLookup = scenario do
None === M.lookup "a" (fromList ([("", 1.0), ("b", 2.0), ("c", 3.0)] : [(Text, Decimal)]))
Some 1.0 === M.lookup "" (fromList ([("", 1.0), ("b", 2.0), ("c", 3.0)] : [(Text, Decimal)]))
None === M.lookup 2 (fromList ([] : [(Int, Text)]))
testNull = scenario do
True === M.null M.empty
False === M.null (insert 5 "a" M.empty)
False === M.null (fromList [(1, "a"), (2, "b"), (3, "c")])
True === M.null (fromList ([] : [(Int, Party)]))
testInsert = scenario do
[(1, True), (2, False), (3, True), (4, False), (5, False)] === toList
(foldl (\a b -> uncurry insert b a) M.empty [(3, True), (1, False), (4, False), (2, True), (5, False), (2, False), (1, True)])
testFilterWithKey = scenario do
[(1, True), (2, False), (3, True)] === toList (M.filterWithKey (\k v -> k < 3 || v) (fromList [(3, True), (1, False), (4, False), (2, True), (5, False), (2, False), (1, True)]))
testDelete = scenario do
[(2, False), (3, True), (4, False), (5, False)] === toList (delete 1 (fromList [(3, True), (1, False), (4, False), (2, True), (5, False), (2, False), (1, True)]))
[(1, False), (2, True)] === toList (delete 3 (fromList [(2, False), (1, True), (2, True), (1, False)]))
testMerge = scenario do
let m1 = fromList [(3, "aa"), (1, "bb"), (4, "cc"), (2, "dd"), (6, "ee")]
let m2 = fromList [(1, "a"), (3, "b"), (2, "c"), (5, "d"), (0, "e")]
[] === toList (merge (\_ v -> Some v) (\_ v -> Some v) (\_ v _ -> Some v) M.empty (M.empty : Map Int Text))
[] === toList (merge (\_ v -> Some v) (\_ v -> Some v) (\_ _ _ -> None) m1 m1)
[(1, "bb"), (3, "aa")] === toList (merge (\_ v -> if v <= "bb" then Some v else None) (\_ v -> Some v) (\_ _ _ -> None) m1 M.empty)
[(1, "a"), (3, "b")] === toList (merge (\_ v -> Some v) (\_ v -> if v <= "bb" then Some v else None) (\_ _ _ -> None) M.empty m2)
[(1,"bb"), (2,"dd"), (3,"aa")] === toList (merge (\_ _ -> None) (\_ _ -> None) (\_ v _ -> Some v) m1 m2)
testMapKeyParty = scenario do
pure $ keyFromText @Party "\"notaparty\""
testMapKeyInt = scenario do
pure $ keyFromText @Int "not-an-int"
testMapKeyDecimal = scenario do
pure $ keyFromText @Decimal "not-a-decimal"

View File

@ -1,8 +0,0 @@
-- Copyright (c) 2021, Digital Asset (Switzerland) GmbH and/or its affiliates.
-- All rights reserved.
-- @SINCE-LF 1.11
-- @WARN DA.Next.Map is deprecated. Please use DA.Map instead.
module NextMapDeprecated where
import DA.Next.Map ()

View File

@ -1,67 +0,0 @@
-- We test for deprecations in NextMapDeprecated
{-# OPTIONS -Wno-deprecations #-}
-- Copyright (c) 2020, Digital Asset (Switzerland) GmbH and/or its affiliates.
-- All rights reserved.
module NextSet where
import DA.Next.Set as S
import DA.Assert
testEmpty = scenario do
0 === size S.empty
[] === toList (S.empty : Set Decimal)
testSize = scenario do
0 === size (fromList ([] : [Decimal]))
3 === size (fromList [1, 2, 3])
testToList = scenario do
[1, 2, 5] === toList (fromList [2, 5, 1])
testFromList = scenario do
False === member 2 (fromList [1, 3, 4])
True === member 3 (fromList [1, 3, 4])
[1] === toList (fromList [1, 1, 1, 1])
testMember = scenario do
False === member "a" (fromList ["", "b", "c"])
True === member "" (fromList ["", "b", "c"])
False === member 2 (fromList [])
testNull = scenario do
True === S.null S.empty
False === S.null (insert 5 S.empty)
False === S.null (fromList [1, 2, 3])
True === S.null (fromList ([] : [Int]))
testInsert = scenario do
[1, 2, 3, 4, 5] === toList (foldl (\a b -> insert b a) S.empty [3, 1, 4, 2, 5, 2, 1])
testFilter = scenario do
[1, 2] === toList (S.filter (<3) (fromList [3, 1, 4, 2, 5, 2, 1]))
testDelete = scenario do
[2, 3, 4, 5] === toList (delete 1 (fromList [3, 1, 4, 2, 5, 2, 1]))
[1, 2] === toList (delete 3 (fromList [2, 1, 2, 1]))
testSingleton = scenario do
[1] === toList (singleton 1)
testUnion = scenario do
[1, 2, 3, 4, 5] === toList (fromList [1, 5, 3] `union` fromList [4, 3, 2])
[2, 4] === toList (S.empty `union` fromList [4, 2])
[1, 3, 5] === toList (fromList [1, 5, 3] `union` S.empty)
[] === toList (S.empty `union` fromList ([] : [Int]))
testIntersection = scenario do
[3, 5, 9] === toList (intersection (fromList [9, 1, 5, 6, 8, 3]) (fromList [4, 3, 7, 2, 5, 9]))
[] === toList (intersection S.empty (fromList [4, 2]))
[] === toList (intersection (fromList [1, 5, 3]) S.empty)
[] === toList (intersection S.empty (fromList ([] : [Int])))
testDifference = scenario do
[1, 6] === toList (difference (fromList [1, 5, 3, 6]) (fromList [4, 3, 2, 5]))
[] === toList (difference S.empty (fromList [4, 2]))
[1, 3, 5] === toList (difference (fromList [1, 5, 3]) S.empty)
[] === toList (difference S.empty (fromList ([] : [Int])))

View File

@ -1,8 +0,0 @@
-- Copyright (c) 2021, Digital Asset (Switzerland) GmbH and/or its affiliates.
-- All rights reserved.
-- @SINCE-LF 1.11
-- @WARN DA.Next.Set is deprecated. Please use DA.Set instead.
module NextSetDeprecated where
import DA.Next.Set ()

View File

@ -67,8 +67,6 @@ damlStdlibTypes ver
]
types = map (bimap LF.ModuleName LF.TypeConName)
[ (["DA", "Random"], ["Minstd"])
, (["DA", "Next", "Set"], ["Set"])
, (["DA", "Next", "Map"], ["Map"])
, (["DA", "Generics"], ["DecidedStrictness"])
, (["DA", "Generics"], ["SourceStrictness"])
, (["DA", "Generics"], ["SourceUnpackedness"])
@ -80,4 +78,3 @@ damlStdlibTypes ver
, (["DA", "Generics"], ["U1"])
, (["DA", "Stack"], ["SrcLoc"])
]

View File

@ -5,7 +5,7 @@ TX #0 1970-01-01T00:00:00Z [Test:48] version: 14
│ referenced by #1:0
│ known to (since): Alice (#0), Bob (#0)
└─> create Test:KeyOps@XXXXXXXX
with: { signatories = DA.Next.Set:Set@XXXXXXXX{ textMap = TextMap(Alice -> <unit>) }, counterParty = 'Bob' }
with: { signatories = DA.Set.Types:Set@XXXXXXXX{ map = GenMap('Alice' -> <unit>) }, counterParty = 'Bob' }
TX #1 1970-01-01T00:00:00Z [Test:49] version: 14
#1:0 version: 14
@ -17,30 +17,30 @@ TX #1 1970-01-01T00:00:00Z [Test:49] version: 14
│ referenced by #2:0, #3:0, #5:0
│ known to (since): Alice (#1), Bob (#1)
└─> create Test:KeyOps@XXXXXXXX
with: { signatories = DA.Next.Set:Set@XXXXXXXX{ textMap = TextMap(Alice -> <unit>, Bob -> <unit>) }, counterParty = 'Bob' }
with: { signatories = DA.Set.Types:Set@XXXXXXXX{ map = GenMap('Alice' -> <unit>, 'Bob' -> <unit>) }, counterParty = 'Bob' }
TX #2 1970-01-01T00:00:00Z [Test:51] version: 14
#2:0 version: 14
│ known to (since): Alice (#2), Bob (#2)
└─> Alice exercises LookupGivenKey:Test:KeyOps@XXXXXXXX on 00420cfea44e4d7f536caf95c9a45394bdc0994e38cbff3b02c444d39bd3ba3d9a
with { actor = 'Alice', keyMaintainers = DA.Next.Set:Set@XXXXXXXX{ textMap = TextMap(Alice -> <unit>) } }
with { actor = 'Alice', keyMaintainers = DA.Set.Types:Set@XXXXXXXX{ map = GenMap('Alice' -> <unit>) } }
children:
#2:1 version: 14
│ known to (since): Alice (#2), Bob (#2)
└─> lookup by key Test:BasicKey@XXXXXXXX
key { textMap = TextMap(Alice -> <unit>) }
key { map = GenMap('Alice' -> <unit>) }
not found
TX #3 1970-01-01T00:00:00Z [Test:54] version: 14
#3:0 version: 14
│ known to (since): Alice (#3), Bob (#3)
└─> Bob exercises LookupGivenKey:Test:KeyOps@XXXXXXXX on 00420cfea44e4d7f536caf95c9a45394bdc0994e38cbff3b02c444d39bd3ba3d9a
with { actor = 'Bob', keyMaintainers = DA.Next.Set:Set@XXXXXXXX{ textMap = TextMap(Alice -> <unit>) } }
with { actor = 'Bob', keyMaintainers = DA.Set.Types:Set@XXXXXXXX{ map = GenMap('Alice' -> <unit>) } }
children:
#3:1 version: 14
│ known to (since): Alice (#3), Bob (#3)
└─> lookup by key Test:BasicKey@XXXXXXXX
key { textMap = TextMap(Alice -> <unit>) }
key { map = GenMap('Alice' -> <unit>) }
not found
TX #4 1970-01-01T00:00:00Z [Test:57] version: 14
@ -48,19 +48,19 @@ TX #4 1970-01-01T00:00:00Z [Test:57] version: 14
│ referenced by #5:1
│ known to (since): Alice (#4)
└─> create Test:BasicKey@XXXXXXXX
with: { owners = DA.Next.Set:Set@XXXXXXXX{ textMap = TextMap(Alice -> <unit>) } }
key { textMap = TextMap(Alice -> <unit>) }
with: { owners = DA.Set.Types:Set@XXXXXXXX{ map = GenMap('Alice' -> <unit>) } }
key { map = GenMap('Alice' -> <unit>) }
TX #5 1970-01-01T00:00:00Z [Test:59] version: 14
#5:0 version: 14
│ known to (since): Alice (#5), Bob (#5)
└─> Alice exercises LookupGivenKey:Test:KeyOps@XXXXXXXX on 00420cfea44e4d7f536caf95c9a45394bdc0994e38cbff3b02c444d39bd3ba3d9a
with { actor = 'Alice', keyMaintainers = DA.Next.Set:Set@XXXXXXXX{ textMap = TextMap(Alice -> <unit>) } }
with { actor = 'Alice', keyMaintainers = DA.Set.Types:Set@XXXXXXXX{ map = GenMap('Alice' -> <unit>) } }
children:
#5:1 version: 14
│ known to (since): Alice (#5), Bob (#5)
└─> lookup by key Test:BasicKey@XXXXXXXX
key { textMap = TextMap(Alice -> <unit>) }
key { map = GenMap('Alice' -> <unit>) }
found 003cb3efc384096d3804f43242d5a20876071b307e08fb06787cf6a3786ee833b2
mustFailAt actAs: {'Bob'} readAs: {} [Test:62]

View File

@ -3,8 +3,8 @@
module Test where
import qualified DA.Next.Set as S
import DA.Next.Set (Set)
import qualified DA.Set as S
import DA.Set (Set)
template BasicKey
with

View File

@ -6,11 +6,7 @@ module UpgradeTrigger where
import DA.Assert
import DA.Foldable
#ifdef DAML_GENMAP && DAML_GENERIC_COMPARISON
import qualified DA.Map as Map
#else
import qualified DA.Next.Map as Map
#endif
import Daml.Trigger
import Daml.Trigger.Assert
import qualified Daml.Script as Script

View File

@ -52,13 +52,8 @@ import DA.Action
import DA.Action.State (execState)
import DA.Foldable (any)
import DA.Functor ((<&>))
#ifdef DAML_GENMAP && DAML_GENERIC_COMPARISON
import DA.Map (Map)
import qualified DA.Map as Map
#else
import DA.Next.Map (Map)
import qualified DA.Next.Map as Map
#endif
import DA.Optional
import Daml.Trigger.Internal
@ -71,11 +66,8 @@ import qualified Daml.Trigger.LowLevel as LowLevel
getContracts : forall a. Template a => ACS -> [(ContractId a, a)]
getContracts acs@(ACS tpls _) = mapOptional fromAny
$ filter (\(cid, _) -> not $ cid `elem` allPending)
#ifdef DAML_GENMAP && DAML_GENERIC_COMPARISON
$ optional [] Map.toList
$ Map.lookup (templateTypeRep @a)
#endif
tpls
$ Map.lookup (templateTypeRep @a) tpls
where
fromAny (cid, tpl) = (,) <$> fromAnyContractId cid <*> fromAnyTemplate tpl
allPending = getPendingContracts acs
@ -86,11 +78,7 @@ getPendingContracts (ACS _ pending) = concatMap snd $ Map.toList pending
getContractById : forall a. Template a => ContractId a -> ACS -> Optional a
getContractById id (ACS tpls pending) = do
let aid = toAnyContractId id
#ifdef DAML_GENMAP && DAML_GENERIC_COMPARISON
implSpecific = Map.lookup aid <=< Map.lookup (templateTypeRep @a)
#else
implSpecific = fmap snd . find ((aid ==) . fst)
#endif
aa <- implSpecific tpls
a <- fromAnyTemplate aa
if any (elem aid) pending then None else Some a

View File

@ -14,13 +14,8 @@ module Daml.Trigger.Assert
) where
import qualified DA.List as List
#ifdef DAML_GENMAP && DAML_GENERIC_COMPARISON
import DA.Map (Map)
import qualified DA.Map as Map
#else
import DA.Next.Map (Map)
import qualified DA.Next.Map as Map
#endif
import qualified DA.Text as Text
import Daml.Trigger hiding (queryContractId)

View File

@ -24,14 +24,9 @@ module Daml.Trigger.Internal
import DA.Action.State
import DA.Functor ((<&>))
#ifdef DAML_GENMAP && DAML_GENERIC_COMPARISON
import DA.Map (Map)
import qualified DA.Map as Map
import DA.Optional (fromOptional)
#else
import DA.Next.Map (Map)
import qualified DA.Next.Map as Map
#endif
import Daml.Trigger.LowLevel hiding (Trigger)
@ -42,13 +37,7 @@ import Daml.Trigger.LowLevel hiding (Trigger)
-- This will change to a Map once we have proper maps in Daml-LF
data ACS = ACS
{ activeContracts :
#ifdef DAML_GENMAP && DAML_GENERIC_COMPARISON
Map.Map TemplateTypeRep
(Map.Map AnyContractId AnyTemplate)
#else
[(AnyContractId, AnyTemplate)]
#endif
{ activeContracts : Map.Map TemplateTypeRep (Map.Map AnyContractId AnyTemplate)
, pendingContracts : Map CommandId [AnyContractId]
}
@ -113,44 +102,27 @@ addCommands m (Commands cid cmds) = Map.insert cid cmds m
-- | HIDE
insertTpl : AnyContractId -> AnyTemplate -> ACS -> ACS
#ifdef DAML_GENMAP && DAML_GENERIC_COMPARISON
insertTpl cid tpl acs = acs { activeContracts = Map.alter addct cid.templateId acs.activeContracts }
where addct = Some . Map.insert cid tpl . fromOptional mempty
#else
insertTpl cid tpl acs = acs { activeContracts = (cid, tpl) :: acs.activeContracts }
#endif
-- | HIDE
#ifdef DAML_GENMAP && DAML_GENERIC_COMPARISON
groupActiveContracts :
[(AnyContractId, AnyTemplate)] -> Map.Map TemplateTypeRep (Map.Map AnyContractId AnyTemplate)
groupActiveContracts = foldr (\v@(cid, _) -> Map.alter (addct v) cid.templateId) Map.empty
where addct (cid, tpl) = Some . Map.insert cid tpl . fromOptional mempty
#else
groupActiveContracts : forall a. a -> a
groupActiveContracts a = a
#endif
-- | HIDE
deleteTpl : AnyContractId -> ACS -> ACS
#ifdef DAML_GENMAP && DAML_GENERIC_COMPARISON
deleteTpl cid acs = acs { activeContracts = Map.alter rmct cid.templateId acs.activeContracts }
where rmct om = do
m <- om
let m' = Map.delete cid m
if Map.null m' then None else Some m'
#else
deleteTpl cid acs = acs { activeContracts = filter (\(cid', _) -> cid /= cid') acs.activeContracts }
#endif
-- | HIDE
lookupTpl : Template a => AnyContractId -> ACS -> Optional a
lookupTpl cid acs = do
#ifdef DAML_GENMAP && DAML_GENERIC_COMPARISON
tpl <- Map.lookup cid =<< Map.lookup cid.templateId acs.activeContracts
#else
(_, tpl) <- find ((cid ==) . fst) acs.activeContracts
#endif
fromAnyTemplate tpl
-- | HIDE

View File

@ -1,6 +1,5 @@
-- Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
-- SPDX-License-Identifier: Apache-2.0
{-# LANGUAGE CPP #-}
{-# LANGUAGE AllowAmbiguousTypes #-}
module Daml.Trigger.LowLevel
@ -47,9 +46,6 @@ module Daml.Trigger.LowLevel
import DA.Action.State
import DA.Action.State.Class
import DA.Functor ((<&>))
#ifndef DAML_GENMAP && DAML_GENERIC_COMPARISON
import DA.Next.Map (MapKey(..))
#endif
import DA.Time (RelTime(..))
import Daml.Script.Free (Free(..), lift, foldFree)
@ -60,9 +56,7 @@ data AnyContractId = AnyContractId
, contractId : ContractId ()
} deriving Eq
#ifdef DAML_GENERIC_COMPARISON
deriving instance Ord AnyContractId
#endif
-- We cant derive the Show instance since TemplateTypeRep does not have a Show instance
-- but it is useful for debugging so we add one that omits the type.
@ -93,11 +87,7 @@ newtype EventId = EventId Text
deriving (Show, Eq)
newtype CommandId = CommandId Text
#ifndef DAML_GENMAP && DAML_GENERIC_COMPARISON
deriving (Show, Eq, Ord, MapKey)
#else
deriving (Show, Eq, Ord)
#endif
data Transaction = Transaction
{ transactionId : TransactionId
@ -272,7 +262,7 @@ liftStateT ma = StateT $ \s -> (,s) <$> ma
instance Action m => Applicative (StateT s m) where
pure a = StateT (\s -> pure (a, s))
f <*> x = f >>= (<$> x)
instance Action m => Action (StateT s m) where
StateT x >>= f = StateT $ \s -> do
(x', s') <- x s

View File

@ -5,11 +5,7 @@
module TemplateIdFilter where
import Prelude hiding (test)
#ifdef DAML_GENMAP && DAML_GENERIC_COMPARISON
import qualified DA.Map as Map
#else
import qualified DA.Next.Map as Map
#endif
import Daml.Trigger
test : RegisteredTemplates -> Trigger ()

View File

@ -6,11 +6,7 @@ module Rule where
import DA.Action
import DA.Assert
#ifdef DAML_GENMAP && DAML_GENERIC_COMPARISON
import qualified DA.Map as Map
#else
import qualified DA.Next.Map as Map
#endif
import Daml.Trigger
import Daml.Trigger.Assert
import qualified Daml.Script as Script