forked from digital-asset/daml
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Interface desugaring cont. (digital-asset#11964)
* Move toInterfaceContractId and fromInterfaceContractId out of Implements class * Split Implements class into single-method classes * Define toInterface outside its class to swap type arguments This allows users to call 'toInterface @interface', since the type of the template can usually be inferred * Move interface classes and functions to DA.Internal.Interface changelog_begin changelog_end
- Loading branch information
Showing
19 changed files
with
180 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
-- Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
-- SPDX-License-Identifier: Apache-2.0 | ||
|
||
{-# LANGUAGE CPP #-} | ||
{-# LANGUAGE NoImplicitPrelude #-} | ||
{-# LANGUAGE ScopedTypeVariables #-} | ||
|
||
-- | MOVE Prelude interface functionality | ||
module DA.Internal.Interface ( | ||
HasInterfaceTypeRep(..), | ||
HasToInterface(..), | ||
HasFromInterface(..), | ||
Implements, | ||
toInterface, | ||
toInterfaceContractId, | ||
fromInterfaceContractId, | ||
) where | ||
|
||
import DA.Internal.Prelude | ||
import DA.Internal.Template.Functions | ||
import DA.Internal.LF | ||
|
||
class HasInterfaceTypeRep i where | ||
interfaceTypeRep : i -> TypeRep | ||
|
||
class HasToInterface t i where | ||
_toInterface : t -> i | ||
|
||
-- Note that this seems identical to the method '_toInterface'. The only difference | ||
-- is the order of the type arguments. This allows `toInterface` to be type-applied to | ||
-- the interface type first, which is usually more convenient. | ||
-- i.e., for a value `asset` of template Asset which implements an interface Token, | ||
-- | ||
-- @ | ||
-- token = toInterface @Token asset | ||
-- @ | ||
-- | ||
-- This way, it's clear to readers what interface is being used, without needing | ||
-- to provide/skip the template type argument, cf. | ||
-- | ||
-- @ | ||
-- token = _toInterface @Asset @Token asset | ||
-- token = _toInterface @_ @Token asset | ||
-- @ | ||
-- | ||
toInterface : forall i t. HasToInterface t i => t -> i | ||
toInterface = _toInterface | ||
|
||
class HasFromInterface t i where | ||
fromInterface : i -> Optional t | ||
|
||
type Implements t i = | ||
( HasInterfaceTypeRep i | ||
, HasToInterface t i | ||
, HasFromInterface t i | ||
) | ||
|
||
toInterfaceContractId : forall i t. HasToInterface t i => ContractId t -> ContractId i | ||
toInterfaceContractId = coerceContractId | ||
|
||
fromInterfaceContractId : forall t i. (HasFromInterface t i, HasFetch i) => ContractId i -> Update (Optional (ContractId t)) | ||
fromInterfaceContractId cid = do | ||
iface <- fetch cid | ||
pure $ | ||
const (coerceContractId cid) <$> fromInterface @t iface |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.