Record Puns/Wildcards

adam vogt vogt.adam at gmail.com
Wed Feb 25 04:13:10 UTC 2015


Hi Ben,

With ghc-7.8.4 I get a different error "Empty record update of:
default_config" when using a wildcard to update a record.

I think you can't use wildcards in record updates because it's harder
(for users and for ghc) to figure out which fields are involved when
you don't name a constructor. If you don't mind naming the constructor
twice, you can do an "update" with:

myC = case defC of
        C { .. } -> C { .. }
          where a = 2
-- myC == C 2 2 3

-- where we have for example
data CType = C { a, b, c :: Int } deriving Show
defC = C 1 2 3

If CType had multiple constructors, I think you'd be better off doing
the update with NamedFieldPuns syntax (defC { a }), or ordinary update
syntax (defC { a = 2 }).

Regards,
Adam


Regards,
Adam

On Tue, Feb 24, 2015 at 9:05 PM, Ben Franksen <ben.franksen at online.de> wrote:
> I just noted that code like
>
> my_config = default_config {..} where
>   name = "my project"
>   description = "some longer text"
>
> gives me a syntax error, even if I have NamedFieldPuns and RecordWildCards
> extensions enabled. It seems that these extensions only work for record
> constructors and not for updating values.
>
> Is there a special reason puns/wildcards are not allowed in record updates?
>
> Cheers
> Ben
> --
> "There are two ways of constructing a software design: One way is to
> make it so simple that there are obviously no deficiencies and the other
> way is to make it so complicated that there are no obvious deficiencies.
> The first method is far more difficult."   ― C.A.R. Hoare
>
>
> _______________________________________________
> Glasgow-haskell-users mailing list
> Glasgow-haskell-users at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/glasgow-haskell-users


More information about the Glasgow-haskell-users mailing list