5

I'm trying to figure out what @ does in an expression like endpoint @"start". Is it part of a language extension perhaps?

I see the follow extensions enabled for the module the function is in.

{-# LANGUAGE DataKinds                  #-}
{-# LANGUAGE DeriveAnyClass             #-}
{-# LANGUAGE DeriveGeneric              #-}
{-# LANGUAGE DerivingStrategies         #-}
{-# LANGUAGE FlexibleContexts           #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE LambdaCase                 #-}
{-# LANGUAGE MultiParamTypeClasses      #-}
{-# LANGUAGE NoImplicitPrelude          #-}
{-# LANGUAGE OverloadedStrings          #-}
{-# LANGUAGE RecordWildCards            #-}
{-# LANGUAGE ScopedTypeVariables        #-}
{-# LANGUAGE TemplateHaskell            #-}
{-# LANGUAGE TypeApplications           #-}
{-# LANGUAGE TypeFamilies               #-}
{-# LANGUAGE TypeOperators              #-}

The full function:

endpoints :: Contract () AuctionSchema Text ()
endpoints = (start' `select` bid' `select` close') >> endpoints
  where
    start' = endpoint @"start" >>= start
    bid'   = endpoint @"bid"   >>= bid
    close' = endpoint @"close" >>= close
Chris Stryczynski
  • 30,145
  • 48
  • 175
  • 286

1 Answers1

10

There are two relevant extensions' documentation to read: TypeApplications and DataKinds. A snippet from the type applications documentation:

The TypeApplications extension allows you to use visible type application in expressions. Here is an example: show (read @Int "5"). The @Int is the visible type application; it specifies the value of the type variable in read's type.

And from the data kinds documentation:

With DataKinds, GHC automatically promotes every datatype to be a kind and its (value) constructors to be type constructors.

I guess you sort of also have to know about Symbol, a type-level representation of strings that is more efficient (but less featureful) than type-level [Char], but I couldn't find a good place in the official documentation to read about it. You can read about it some in the GHC.TypeLits haddocks.

Daniel Wagner
  • 145,880
  • 9
  • 220
  • 380
  • 1
    Thanks, yes seems to be correct. Related answer to this is also here: https://stackoverflow.com/questions/61482257/besides-as-pattern-what-else-can-mean-in-haskell – Chris Stryczynski Apr 12 '21 at 14:02