记录可以有大写字段吗?

时间:2017-03-20 04:14:49

标签: syntax record capitalization purescript

根据我的理解,在purescript中,{foo :: Foo}去了Record ("foo" :: Foo)。我可以制作像Record ("F" :: Foo)这样的东西吗?如何看待记录访问语法? thing.F语法有效吗?

1 个答案:

答案 0 :(得分:3)

引用字段正是这样做的方式,都在类型中:

<seqlist>
  <item><para id="p7.1"><emphasis>JRK Type 1</emphasis>: (NSP XX-XX-XXX-XXXX)
outputs:
   <seqlist>
     <item><para id="p7.1.1">12 V or 15 V,0-5A</para></item>
     <item><para id="p7.1.2">12 V or 15 V,0-5A</para></item>
   </seqlist></para>
      <para>Both at 120 W maximum output power.</para><para>The outputs are isolated, permitting parallel or serial connection to provide power as required.</para></item>
    <item><para id="p7.2"><emphasis>JRK Type 2:</emphasis> (NSN 6130-99-788-6945) outputs:</para>
   <seqlist>
     <item><para id="p7.2.1">5 V, 0 - 30 A</para></item>
     <item><para id="p7.2.2">12 V, 0 - 0.5 A</para></item>
   </seqlist><para>Both at 120 W maximum output power.</para>
  <para>The 12 V outputs are measured with respect to a common 0 V line but these are isolated from the 5 V output.</para></item>
</seqlist>

在访问者/模式中:

type MyRecord = { "Usually impossible field name" :: Boolean }

以这种方式引用字段允许您使用大写字母,符号,数字等命名记录字段。

这与JavaScript中的make :: Boolean -> MyRecord make = { "Usually impossible field name": _ } get :: MyRecord -> Boolean get = _."Usually impossible field name" update :: MyRecord -> Boolean -> MyRecord update = _ { "Usually impossible field name" = _ } 有点类似,但您只能将字符串文字用于属性名称而不是任意值。