-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move BuildTxWith and associated types to a new module to avoid cyclical
dependencies
- Loading branch information
Showing
2 changed files
with
49 additions
and
32 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
{-# LANGUAGE DataKinds #-} | ||
{-# LANGUAGE DerivingVia #-} | ||
{-# LANGUAGE DisambiguateRecordFields #-} | ||
{-# LANGUAGE FlexibleContexts #-} | ||
{-# LANGUAGE FlexibleInstances #-} | ||
{-# LANGUAGE GADTs #-} | ||
{-# LANGUAGE RankNTypes #-} | ||
{-# LANGUAGE ScopedTypeVariables #-} | ||
{-# LANGUAGE StandaloneDeriving #-} | ||
|
||
module Cardano.Api.Internal.Tx.BuildTxWith | ||
( BuildTxWith (..) | ||
, BuildTx | ||
, ViewTx | ||
, buildTxWithToMaybe | ||
) | ||
where | ||
|
||
-- ---------------------------------------------------------------------------- | ||
-- Building vs viewing transactions | ||
-- | ||
|
||
data ViewTx | ||
|
||
data BuildTx | ||
|
||
data BuildTxWith build a where | ||
ViewTx :: BuildTxWith ViewTx a | ||
BuildTxWith :: a -> BuildTxWith BuildTx a | ||
|
||
instance Functor (BuildTxWith build) where | ||
fmap _ ViewTx = ViewTx | ||
fmap f (BuildTxWith x) = BuildTxWith (f x) | ||
|
||
instance Applicative (BuildTxWith ViewTx) where | ||
pure _ = ViewTx | ||
_ <*> _ = ViewTx | ||
|
||
instance Applicative (BuildTxWith BuildTx) where | ||
pure = BuildTxWith | ||
(BuildTxWith f) <*> (BuildTxWith a) = BuildTxWith (f a) | ||
|
||
buildTxWithToMaybe :: BuildTxWith build a -> Maybe a | ||
buildTxWithToMaybe ViewTx = Nothing | ||
buildTxWithToMaybe (BuildTxWith a) = Just a | ||
|
||
deriving instance Eq a => Eq (BuildTxWith build a) | ||
|
||
deriving instance Show a => Show (BuildTxWith build a) |