On Tuesday, February 28, 2017 at 1:24:32 AM UTC, Aaron Strick wrote:
>
> Another solution, one which developers it seems tend towards, is using 
> extensible types to represent the states:
>
> ```
> type alias PersonBase a =
>   { a
>     | id : Int
>     , name : Int
>   }
>
> type alias Person =
>   PersonBase { address : Address }
>
> type alias HomelessPerson =
>   PersonBase {}
> ```
>
> This enables us to give raise decoding errors, and to make impossible 
> states impossible. It becomes unwieldy very fast to start creating the 
> constructors for when the records grow in size.
>

I think trying to represent sub-types using extensible records in Elm is a 
mistake and is going to lead to all sorts of other difficulties in your 
code. I explored using extensible records for this purpose in this thread, 
and basically came to the conclusion that as elm does not support 
sub-typing (and cannot without losing full type inference), they should be 
avoided:

https://groups.google.com/forum/#!topic/elm-discuss/NVoWA0ZYZNM 

How about decoding to this data structure:

type Person = 
   Housed { id: Int, name: Int, address: Address }
 | Homeless { id: Int, name: Int }

or

type alias Named = { id: Int, name: Int }

type Person = 
   Housed Named Address
 | Homeless Named

?

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to