literal default value for an unknown type

Derek Elkins ddarius@hotpop.com
Tue, 8 Jul 2003 22:19:49 -0400


On Tue, 8 Jul 2003 23:16:33 -0300
"Andre W B Furtado" <andrefurtado@ieg.com.br> wrote:

> Is it possible replace the question mark in the following code in
> order to make defaultMyType return a "don't care" value for b?
> 
> data MyType t = MyType { a :: Int, b :: t}
> 
> defaultMyType :: MyType
> defaultMyType = MyType {a = 0, b = ?}
> 

First you do need the type parameter (:: MyType t).

Then you have (at least) three options.

You can replace the ? with undefined.  You can omit b altogether in the
record construction and get the same effect as the first option, or you
could have b :: Maybe t and have the ? be Nothing.  Which (of the
really two options) is best depends on how you intend to use the record.