您需要只使用没有任何其他数据类型(自定义或内置)的函数来实现不可变字典。字典必须由类Eq的任何数据类型索引,并且包含任意类型的值,但是字典中的所有值都应该是相同类型的。
下面是一些用法示例:
dict `access` True -- returns value of key True
dict `access` "y" -- returns value of key "y"
(update "x" 10 dict) `access` "x" -- returns 10 for any dict发布于 2014-05-15 10:21:32
update key1 value obj = \key2 -> if key2 == key1 then value else obj key2
access = id鉴于上述定义,您的示例应该有效。此外,还可以将空字典定义为const x,其中x是字典中未包含的键的默认值。
https://codegolf.stackexchange.com/questions/27074
复制相似问题