literal default value for an unknown type
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 = ?} Cheers, -- Andre
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.
On Tue, Jul 08, 2003 at 10:19:49PM -0400, Derek Elkins wrote:
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).
Maybe what's wanted is this? defaultMyType :: MyType a defaultMyTpe = MyType {a = 0, b = undefined} Peace, Dylan
participants (3)
-
Andre W B Furtado -
Derek Elkins -
Dylan Thurston