1
私はelm(0.18)で拡張可能なレコードを使用しています。私のモデルには次のタイプが含まれています:Elmの拡張可能なレコードのデコード
type alias Cat c =
{ c
| color : String
, age : Int
, name : String
, breed : String
}
type alias SimpleCat =
Cat {}
type alias FeralCat =
Cat
{ feral : Bool
, spayed : Bool
}
今、これらのタイプをデコーダに渡すことができます。私は通常、elm-decode-pipelineライブラリ"NoRedInk/elm-decode-pipeline": "3.0.0 <= v < 4.0.0"
を使用します。
私はこのタイプの設定:
catDecoder : Decode.Decoder SimpleCat
catDecoder =
Pipeline.decode SimpleCat
|> Pipeline.required "color" Decode.string
|> Pipeline.required "age" Decode.int
|> Pipeline.required "name" Decode.string
|> Pipeline.required "breed" Decode.string
をしかし、私はこのエラーを取得する:
-- NAMING ERROR --------------------------------------------- ./src/Decoders.elm
Cannot find variable `SimpleCat`
141| Pipeline.decode SimpleCat
これは私の非伸縮タイプでは発生しません。これらのタイプをデコーダで使用する方法はありますか? (elm-decode-pipelineが好きですが、別の方法があるかどうかを知りたいのですが)
私はそれを恐れていました。これらのすべてのタイプのデコーダが必要であると仮定すると、そのテクニックは(拡張性のない)レコードを作成するだけのメリットがありますか? –
/Elmがコンストラクタとして拡張可能な形式で定義された型を使用できるようになるまでは、 'Cat a'エイリアスとまだ一致しているので、' FeralCat'の定義のすべてのプロパティをリストする方が良いかもしれません –