[Haskell-beginners] data type design question

Rafael Gustavo da Cunha Pereira Pinto rafaelgcpp at gmail.com
Wed Jul 30 19:50:50 EDT 2008


Those are bittorrent types, as defined by the protocol "specifications"

I was thinking:

data TPrimitive= TString String | TInt Integer
data TComplex = TList [TPrimitive] | TDict [(String,TPrimitive)]
data T = TPrimitive | TComplex


Would that work?


On Wed, Jul 30, 2008 at 16:28, Jason Dusek <jason.dusek at gmail.com> wrote:

>  A data declaration _defines_ type constructors. You describe
>  what types those constructors can accept, so this:
>
>    data T
>      = TString String
>      | TInt Integer
>       | TList [T]
>      | TDict [(TString, T)]
>
>  actually doesn't make any sense -- the list holds what? Holds
>  tuples of `TString` and `T`. What type is `TString` ? It's not
>  a type, it's a constructor! So you need to make it a type.
>
>  Also, it is not clear to me why the `TDict` can not just map
>  `String`s to `T`s -- if you get a `TString` in the course of
>  parsing, you can unwrap it.
>
> --
> _jsn
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>



-- 
Rafael Gustavo da Cunha Pereira Pinto
Electronic Engineer, MSc.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20080730/b77fbffd/attachment-0001.htm


More information about the Beginners mailing list