1

Let's say I have the following sort of type definitions:

type alias EntityBase =
    { id: Int
    , name : String
    }


-- Derived types

type alias PersonSpecfic entityBase =
    { entityBase 
        | age: Int
        , address : String
    }
type alias Person = PersonSpecfic EntityBase

Are there any constructor functions for the types Person / PersonSpecfic in the current version of Elm (0.16)?

(the compiler says "Cannot find variable ``PersonSpecfic``")

This is relevant to be able to create Json decoders for the type hierarchy.

Gabor
  • 1,656
  • 1
  • 16
  • 28
  • 1
    The code you posted seems to work fine for me: http://share-elm.com/sprout/56df2267e4b070fd20daa505 (share-elm is only Elm 0.15, but I tested the same code locally with 0.16) – robertjlooby Mar 08 '16 at 19:05
  • @robertjlooby the code I posted only includes the type definitions. Normally the name of the type also serves as a constructor function, but not in case "generic"/"extended" record definitions. – Gabor Apr 13 '16 at 15:56

2 Answers2

1

Since elm 0.16, record extension does not exist in the language anymore.

Partially as a side effect of that, there are no constructor functions for record types defined in "generic"/"extended" fashion.

More details can be found on this thread: https://groups.google.com/forum/#!searchin/elm-discuss/constructor/elm-discuss/AaL8iLjhEdU/JSAXV2oACgAJ

Gabor
  • 1,656
  • 1
  • 16
  • 28
0

Yea, that looks like a compiler bug. You could always create your own constructor function to use in JSON decoding:

createPerson : Int -> String -> Int -> String -> Person
createPerson id name age address =
  { id = id
  , name = name
  , age = age
  , address = address
  }
Chad Gilbert
  • 36,115
  • 4
  • 89
  • 97