Skip to main content
2 of 5
more tags

How string value is being transformed to a type constructor?

According type applications, this extension allows to give explicit type arguments to a polymorphic function.

type VestingSchema =
             Endpoint "give" GiveParams
         .\/ Endpoint "grab" ()
-- ...
endpoints :: Contract () VestingSchema Text ()
endpoints = awaitPromise (give' `select` grab') >> endpoints
   where
     give' = endpoint @"give" give
     grab' = endpoint @"grab" $ const grab

This does not allows to give values to a polymorphic function, so I have figured out that actually those "strings" at @"give" and @"grab" are actually type constructors, because the type Endpoint has this type/kind signature:

type Endpoint :: ghc-prim-0.6.1:GHC.Types.Symbol
                 -> * -> row-types-1.0.1.2:Data.Row.Internal.Row *
type Endpoint l a =
  l
  row-types-1.0.1.2:Data.Row.Internal..== (Wallet.Types.EndpointValue
                                             a,
                                           Plutus.Contract.Effects.ActiveEndpoint)
  :: row-types-1.0.1.2:Data.Row.Internal.Row *
        -- Defined in ‘Plutus.Contract.Request

So that l is a Symbol. Why this is working with TypeApplications? I can use this "give" and "grab" as type constructors anywhere in my code?