Ticket #2759 (closed bug: fixed)

Opened 5 years ago

Last modified 4 years ago

Data.Generics.ConstrRep isn't general enough

Reported by: guest Owned by: dreixel
Priority: normal Milestone: 6.12 branch
Component: libraries (other) Version: 6.10.1
Keywords: Cc: jpm@…, lennart@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Difficulty: Unknown
Test Case: Blocked By:
Blocking: Related Tickets:

Description

The type ConstrRep? in Data.Generics is used to represent constructors for types. The FloatConstr? constructor is the one used for all kinds of floating point primitives. But FloatConstr? has an argument of type Double. This limits the primitive floating point types to those that are accurately representable as a Double. In other places in Haskell where an accurate and generic floating point value is needed the type Rational is used. It should be used here too.

Attachments

fix2759.patch Download (89.7 KB) - added by dreixel 5 years ago.
fix2759base.patch Download (4.2 KB) - added by dreixel 5 years ago.
fix2759base.2.patch Download (7.6 KB) - added by dreixel 4 years ago.

Change History

Changed 5 years ago by simonpj

  • cc jpm@… added
  • difficulty set to Unknown
  • owner set to jose magalhaes

Assigning to Jose.

Changed 5 years ago by igloo

  • component changed from Compiler to libraries (other)
  • milestone set to 6.12 branch

Changed 5 years ago by dreixel

Changed 5 years ago by dreixel

Changed 5 years ago by dreixel

  • owner changed from jose magalhaes to dreixel
  • status changed from new to assigned

Attached patches to fix it. A user visible change is the type of function mkFloatConstr. It was previously 'DataType -> Double -> Constr', it's now '(Real a) => DataType -> a -> Constr'. This should cause no problems with existing code, though.

Changed 4 years ago by igloo

Hmm, it seems inconsistent to have these two:

mkIntConstr :: DataType -> Integer -> Constr
mkFloatConstr :: (Real a) => DataType -> a -> Constr

Shouldn't it either be

mkIntConstr :: DataType -> Integer -> Constr
mkFloatConstr :: DataType -> Rational -> Constr

or

mkIntConstr :: (Integral a) => DataType -> a -> Constr
mkFloatConstr :: (Real a) => DataType -> a -> Constr

?

The *Float* names are also confusing, but presumably the plan is to transition away from them?

Changed 4 years ago by dreixel

The problem with

mkFloatConstr :: DataType -> Rational -> Constr

is that it breaks existing code which uses 'mkFloatConstr'. I would then prefer to change 'mkIntConstr' to

mkIntConstr :: (Integral a) => DataType -> a -> Constr

instead.

I agree that the names are not ideal. We could also make them 'mkIntegralConstr' and 'mkRealConstr', deprecating the old ones, I guess.

Changed 4 years ago by dreixel

Changed 4 years ago by dreixel

Attached a new patch which deprecates mkIntConstr and mkFloatConstr, and introduces mkIntegralConstr and mkRealConstr.

Changed 4 years ago by igloo

  • status changed from assigned to closed
  • resolution set to fixed

Applied, thanks!

Note: See TracTickets for help on using tickets.