GADTs in the wild

Christian Maeder Christian.Maeder at dfki.de
Wed Aug 15 18:27:19 CEST 2012


Am 15.08.2012 17:58, schrieb Felipe Almeida Lessa:
> On Wed, Aug 15, 2012 at 12:54 PM, Christian Maeder
> <Christian.Maeder at dfki.de> wrote:
>> Well, "Either" was an adhoc choice and should be application specific.
>> Another h98 solution would be to keep the common part in a single
>> constructor:
>>
>>    data UserOrAppData = AppData | UserData UserId UTCTime
>>    data AccessToken = AccessToken UserOrAppData AccessTokenData
>
> This is a non-solution since you can't specify anymore that you want
> an user access token but not an app access token.
>
>> or: data AccessToken a = AccessToken a AccessTokenData
>
> And this one brings us the Either again (although on fewer places).
> Most functions would be able to get a `AccessToken a` because they
> don't care about what you called `UserData` above.  However, some
> other functions (such as isValid) do care about that and would need
> `Either (AccessToken AppData) (AccessToken UserData)`.

This type does not share the AccessTokenData and corresponds to 
"AccessToken UserOrAppData".

>
> That's not to say that we *couldn't* avoid GADTs.  We certainly could.
>   But GADTs allow us to have our cake and eat it, too =).

Sure, but portability is a value, too.

C.

>
> Cheers,
>




More information about the Glasgow-haskell-users mailing list