xyncro / chiron

JSON for F#
https://xyncro.tech/chiron
MIT License
175 stars 41 forks source link

How do you read a list of a structure? #13

Closed haf closed 9 years ago

haf commented 9 years ago

How do I read a collection of a known type?

type Folder =
  { _url : Uri option
    email : string
    files : File list
    folders : Folder list
    id : string
    name : string }

  static member FromJson (_ : Folder) =
    (fun url email files folders id name -> 
      { _url = Some (Uri url)
        email = email
        files = files
        folders = folders
        id = id
        name = name })
    <!> Json.read "@url"
    <*> Json.read "Email"
    <*> Json.read "Files" // error: no overloads match...
    <*> Json.read "Folders"
    <*> Json.read "Id"
    <*> Json.read "Name"

I'm trying to read a File and a Folder list; File already has ToJson and FromJson.

haf commented 9 years ago

Came from bad FromJson on File. Remember, children, to check your function signatures especially when using Damas-Hindley-Milner type inference.