GADTs in the wild

Christian Maeder Christian.Maeder at dfki.de
Wed Aug 15 17:54:04 CEST 2012


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

or: data AccessToken a = AccessToken a AccessTokenData

C.

Am 14.08.2012 18:32, schrieb Felipe Almeida Lessa:
> 2012/8/14 Christian Maeder <Christian.Maeder at dfki.de>:
>> Why not use plain h98?
>>
>>    data UserAccessToken = UserAccessToken UserId AccessTokenData UTCTime
>>    data AppAccessToken = AppAccessToken AccessTokenData
>>
>>    type AccessToken = Either UserAccessToken AppAccessToken
>
> Convenience.  It's better to write
>
>    case token of
>      UserAccessToken ... -> ...
>      AppAccessToken ... -> ...
>
> than
>
>    case token of
>      Left (UserAccessToken ...) -> ...
>      Right (UserAccessToken ...) -> ...
>
> Also, it's easier to write
>
>    isValid token
>
> than
>
>    isValid (Right token)  -- or is it Left?
>
> Cheers, =)
>



More information about the Glasgow-haskell-users mailing list