- Overview
- Tutorials
- Getting started
- Get started with Canton and the JSON Ledger API
- Get Started with Canton, the JSON Ledger API, and TypeScript
- Get started with Canton Network App Dev Quickstart
- Get started with smart contract development
- Basic contracts
- Test templates using Daml scripts
- Build the Daml Archive (.dar) file
- Data types
- Transform contracts using choices
- Add constraints to a contract
- Parties and authority
- Compose choices
- Handle exceptions
- Work with dependencies
- Functional programming 101
- The Daml standard library
- Test Daml contracts
- Next steps
- Application development
- Getting started
- Development how-tos
- Component how-tos
- Explanations
- References
- Application development
- Smart contract development
- Daml language cheat sheet
- Daml language reference
- Daml standard library
- DA.Action.State.Class
- DA.Action.State
- DA.Action
- DA.Assert
- DA.Bifunctor
- DA.Crypto.Text
- DA.Date
- DA.Either
- DA.Exception
- DA.Fail
- DA.Foldable
- DA.Functor
- DA.Internal.Interface.AnyView.Types
- DA.Internal.Interface.AnyView
- DA.List.BuiltinOrder
- DA.List.Total
- DA.List
- DA.Logic
- DA.Map
- DA.Math
- DA.Monoid
- DA.NonEmpty.Types
- DA.NonEmpty
- DA.Numeric
- DA.Optional
- DA.Record
- DA.Semigroup
- DA.Set
- DA.Stack
- DA.Text
- DA.TextMap
- DA.Time
- DA.Traversable
- DA.Tuple
- DA.Validation
- GHC.Show.Text
- GHC.Tuple.Check
- Prelude
- Smart contract upgrading reference
- Glossary of concepts
DA.Bifunctor¶
Typeclasses¶
class Bifunctor p where
A bifunctor is a type constructor that takes two type arguments and is a functor in both arguments. That is, unlike with
Functor
, a type constructor such asEither
does not need to be partially applied for aBifunctor
instance, and the methods in this class permit mapping functions over the Left value or theRight
value, or both at the same time.It is a bifunctor where both the first and second arguments are covariant.
You can define a
Bifunctor
by either defining bimap or by defining both first and second.If you supply bimap, you should ensure that:
`bimap identity identity` ≡ `identity`If you supply first and second, ensure:
first identity ≡ identity second identity ≡ identityIf you supply both, you should also ensure:
bimap f g ≡ first f . second gBy parametricity, these will ensure that:
bimap (f . g) (h . i) ≡ bimap f h . bimap g i first (f . g) ≡ first f . first g second (f . g) ≡ second f . second g
- bimap
: (a -> b) -> (c -> d) -> p a c -> p b d
Map over both arguments at the same time.
bimap f g ≡ first f . second gExamples:
>>> bimap not (+1) (True, 3) (False,4) >>> bimap not (+1) (Left True) Left False >>> bimap not (+1) (Right 3) Right 4
- first
: (a -> b) -> p a c -> p b c
Map covariantly over the first argument.
first f ≡ bimap f identityExamples:
>>> first not (True, 3) (False,3) >>> first not (Left True : Either Bool Int) Left False
- second
: (b -> c) -> p a b -> p a c
Map covariantly over the second argument.
second ≡ bimap identityExamples:
>>> second (+1) (True, 3) (True,4) >>> second (+1) (Right 3 : Either Bool Int) Right 4instance Bifunctor ()
instance Bifunctor x1
instance Bifunctor (x1, x2)
instance Bifunctor (x1, x2, x3)
instance Bifunctor (x1, x2, x3, x4)
instance Bifunctor (x1, x2, x3, x4, x5)