gpt4 book ai didi

F# 构造常量分组

转载 作者:行者123 更新时间:2023-12-05 00:31:16 25 4
gpt4 key购买 nike

我有几个带有标题的页面,我希望能够将这些标题定义为某种枚举中的字符串常量。像这样

pageTitles =
| HOME = "Home"
| SALES = "Sales"
| MARKETING = "Marketing"
| LOGOUT = "Logout"

然后像这样使用它:

if title = pageTitles.SALES then
//Goto sales

最佳答案

结合 Daniel/Tomas 的建议:

module PageTitles =
[<Literal>]
let HOME = "Home"
[<Literal>]
let SALES = "Sales"
...
open PageTitles
...
match title with
| HOME -> // goto home
| SALES -> // goto sales

关于F# 构造常量分组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4891438/

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