gpt4 book ai didi

haskell - 在 Haskell 的表达式中 @ 符号有什么作用?

转载 作者:行者123 更新时间:2023-12-03 15:41:08 25 4
gpt4 key购买 nike

我试图弄清楚 @endpoint @"start" 这样的表达式.它可能是语言扩展的一部分吗?
我看到为该功能所在的模块启用了以下扩展。

{-# 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 #-}
完整功能:
endpoints :: Contract () AuctionSchema Text ()
endpoints = (start' `select` bid' `select` close') >> endpoints
where
start' = endpoint @"start" >>= start
bid' = endpoint @"bid" >>= bid
close' = endpoint @"close" >>= close

最佳答案

有两个相关的扩展文档可供阅读: TypeApplications DataKinds .类型应用程序文档的片段:

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.


从数据种类文档中:

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


我猜你也应该知道 Symbol ,字符串的类型级别表示,比类型级别更有效(但功能更少) [Char] ,但我在官方文档中找不到好地方来阅读它。您可以在 GHC.TypeLits haddocks 中了解它的一些内容。 .

关于haskell - 在 Haskell 的表达式中 @ 符号有什么作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67059638/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com