gpt4 book ai didi

elm - 你能在榆树中使用字符串进行记录访问吗?

转载 作者:行者123 更新时间:2023-12-01 01:26:53 25 4
gpt4 key购买 nike

如果我有一个看起来像记录中字段名称的字符串,我可以使用它以某种方式获取数据吗?像这样的东西:

."name".toKey bill 
bill.(asSymbol "name")

-

song =
{ title = "foot", artist = "barf", number = "13" }

fieldsILike : List String
fieldsILike =
[ "title", "artist" ]


val song key =
.key song

foo = List.map (val song) fieldsILike --> should be ["foot", "barf"]

最佳答案

不,但你可以使用 Dict

import Dict exposing (get ,fromList)

song = fromList [ ("title", "foot"), ("artist", "barf") ]

get "title" song -- Just "foot"
get "artist" song -- Just "barf"
get "test" song -- Nothing

关于elm - 你能在榆树中使用字符串进行记录访问吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35499847/

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