Remove DA.Upgrade module (#4839)

Given that Generic instances are not supported cross-SDK this module
only causes confusion and I’d rather remove it.

changelog_begin
changelog_end
This commit is contained in:
mergify[bot] 2020-03-05 16:30:54 +00:00 committed by GitHub
parent 950d8c3501
commit 60013a1535
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 0 additions and 174 deletions

View File

@ -1,126 +0,0 @@
-- Copyright (c) 2020 The DAML Authors. All rights reserved.
-- SPDX-License-Identifier: Apache-2.0
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE OverlappingInstances #-}
module DA.Upgrade
( iso
, Convertible(..)
, Iso
, GenConvertible
, MetaEquiv
)
where
import DA.Generics
----------------------------------------------------------------------------------------------------
-- Data type conversion
----------------------------------------------------------------------------------------------------
-- | Types, for which there exists a conversion.
class Convertible a b where
convert : a -> b
-- | HIDE
default convert : (Generic a repA, Generic b repB, GenConvertible repA repB) => a -> b
convert = to . cv . from
-- | Generically convert data types that are isomorphic and have the same meta-data up to package id.
genConvert : (Generic a repA, Generic b repB, GenConvertible repA repB) => a -> b
genConvert = to . cv . from
-- | Generic representations that are isomorphic and have the same meta-data up to package id.
class GenConvertible a b where
cv : a x -> b x
-- copy values
instance GenConvertible V1 V1 where cv = identity
instance GenConvertible U1 U1 where cv = identity
-- Isomorphic types in different packages
instance (MetaEquiv c1 c2, GenConvertible f1 f2) => GenConvertible (M1 i1 c1 f1) (M1 i2 c2 f2) where
cv = M1 . cv . unM1
-- products
instance (GenConvertible a1 a2, GenConvertible b1 b2) => GenConvertible (a1 :*: b1) (a2 :*: b2) where
cv ~(P1 a b) = P1 (cv a) (cv b)
-- product embeddings
instance (GenConvertible a1 a2) => GenConvertible a1 (a2 :*: Opt b s) where
cv a = P1 (cv a) genNone
-- product projections
instance GenConvertible a1 a2 => GenConvertible (a1 :*: Opt b1 s) a2 where
cv ~(P1 a (M1 (K1 {unK1 = None}))) = cv a
-- cv ~(P1 a (M1 (K1 {unK1 = Some _b}))) = error "This conversion would have introduced data loss"
-- sums
instance (GenConvertible a1 a2, GenConvertible b1 b2) => GenConvertible (a1 :+: b1) (a2 :+: b2) where
cv (L1 a) = L1 $ cv a
cv (R1 b) = R1 $ cv b
-- recursion
instance GenConvertible (K1 R c) (K1 R c) where cv = identity
instance GenConvertible c1 c2 => GenConvertible (K1 R (c1 x)) (K1 R (c2 x)) where
cv = K1 . cv . unK1
instance (Generic x repX, Generic y repY, GenConvertible repX repY) => GenConvertible (K1 R x) (K1 R y) where
cv = K1 . genConvert . unK1
-- | This class describes meta-data that is equal up to package id.
class MetaEquiv (m1: Meta) (m2: Meta)
instance MetaEquiv m m
instance MetaEquiv ('MetaData ('MetaData0 n mod p1 'True)) ('MetaData ('MetaData0 n mod p2 'True))
instance MetaEquiv ('MetaData ('MetaData0 n mod p1 'False)) ('MetaData ('MetaData0 n mod p2 'False))
-- Isomorphism between two isomorphic data types.
iso : (Generic a repA, Generic b repB, Iso repA repB) => a -> b
iso = to . isom . from
-- Isomorphic representations ignoring meta-data.
class Iso a b where
isom : a x -> b x
-- copy values
instance Iso V1 V1 where isom = identity
instance Iso U1 U1 where isom = identity
-- Isomorphic types
instance (Iso f1 f2) => Iso (M1 i1 c1 f1) (M1 i2 c2 f2) where
isom = M1 . isom . unM1
-- products
instance (Iso a1 a2, Iso b1 b2) => Iso (a1 :*: b1) (a2 :*: b2) where
isom ~(P1 a b) = P1 (isom a) (isom b)
-- sums
instance (Iso a1 a2, Iso b1 b2) => Iso (a1 :+: b1) (a2 :+: b2) where
isom (L1 a) = L1 $ isom a
isom (R1 b) = R1 $ isom b
-- recursion
instance Iso (K1 R c) (K1 R c) where isom = identity
instance Iso c1 c2 => Iso (K1 R (c1 x)) (K1 R (c2 x)) where
isom = K1 . isom . unK1
instance (Generic x repX, Generic y repY, Iso repX repY) => Iso (K1 R x) (K1 R y) where
isom = K1 . iso . unK1
----------------------------------------------------------------------------------------------------
-- Optional fields
----------------------------------------------------------------------------------------------------
type Opt a s = S1
('MetaSel
('MetaSel0
('Some s)
'NoSourceUnpackedness
'NoSourceStrictness))
(Rec0 (Optional a))
-- Generic representation of an optional field with a `None` value
genNone : Opt a s p
genNone = M1 $ K1 {unK1 = None}

View File

@ -49,6 +49,5 @@ import DA.TextMap
import DA.Time
import DA.Traversable
import DA.Tuple
import DA.Upgrade
import DA.Validation
import Prelude

View File

@ -1,22 +0,0 @@
-- Copyright (c) 2020, Digital Asset (Switzerland) GmbH and/or its affiliates.
-- All rights reserved.
module Isomorphism where
import DA.Upgrade
import DA.Generics
data TreeA = LeafA Int | NodeA NodeA0 deriving Generic
data NodeA0 = NodeA0 {lA : Int, rA : Text} deriving Generic
data TreeB = LeafB Int | NodeB NodeB0 deriving Generic
data NodeB0 = NodeB0 {lB : Int, rB : Text} deriving Generic
treeA : TreeA
treeA = NodeA (NodeA0 1 "hello world")
-- Test whether the isomorphism function can be generated for isomorphic data types.
treeB : TreeB
treeB = iso treeA

View File

@ -1,24 +0,0 @@
-- Copyright (c) 2020, Digital Asset (Switzerland) GmbH and/or its affiliates.
-- All rights reserved.
-- @ERROR No instance for (Generic Int repX0) arising from a use of iso
module IsomorphismFail where
import DA.Upgrade
import DA.Generics
data TreeA = LeafA Int | NodeA NodeA0 deriving Generic
data NodeA0 = NodeA0 {lA : Int, rA : Int} deriving Generic
data TreeB = LeafB Int | NodeB NodeB0 deriving Generic
data NodeB0 = NodeB0 {lB : Int, rB : Text} deriving Generic
treeA : TreeA
treeA = NodeA (NodeA0 1 2)
-- This should not work because TreeA and Tree are not isomorphic.
treeB : TreeB
treeB = iso treeA

View File

@ -51,7 +51,6 @@ EOF
)
else
$DIFF -b -u <(get_serializable_types $stdlib) <(cat <<EOF
"DA.Upgrade:MetaEquiv"
"DA.Random:Minstd"
"DA.Next.Set:Set"
"DA.Next.Map:Map"