[英]What does the @ symbol do within an expression in Haskell?
I'm trying to figure out what @
does in an expression like endpoint @"start"
.我试图弄清楚@
在endpoint @"start"
这样的表达式中做了什么。 Is it part of a language extension perhaps?它可能是语言扩展的一部分吗?
I see the follow extensions enabled for the module the function is in.我看到为 function 所在的模块启用了以下扩展。
{-# 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:完整的 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
There are two relevant extensions' documentation to read: TypeApplications
and DataKinds
.有两个相关的扩展文档可供阅读: TypeApplications
和DataKinds
。 A snippet from the type applications documentation:类型应用程序文档的片段:
The
TypeApplications
extension allows you to use visible type application in expressions.TypeApplications
扩展允许您在表达式中使用可见类型应用程序。 Here is an example:show (read @Int "5")
.这是一个示例:show (read @Int "5")
。 The@Int
is the visible type application;@Int
是可见类型应用程序; it specifies the value of the type variable inread
's type.它以read
的类型指定类型变量的值。
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.使用DataKinds
,GHC 自动将每个数据类型提升为一种类型,并将其(值)构造函数提升为类型构造函数。
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.我想你也必须了解Symbol
,一种类型级别的字符串表示,比类型级别[Char]
更有效(但功能更少),但我在官方文档中找不到一个好地方阅读它。 You can read about it some in the GHC.TypeLits
haddocks .您可以在GHC.TypeLits
中阅读有关它的一些信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.