Skip to content

Commit

Permalink
Add notes about defaulting with FloatConvert
Browse files Browse the repository at this point in the history
  • Loading branch information
bredelings committed Jan 4, 2025
1 parent b7dc7ac commit 93ba413
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions haskell/Data/Floating/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,28 @@ instance FloatConvert Int Double where

instance {-# INCOHERENT #-} FloatConvert a a where
toFloating x = x

{- NOTE: Problems with defaults.
The geometric distribution is currently specified as:
geometric :: Double -> Geometric
geometric pSuccess = Geometric (toFloating pSuccess)
We need to specify that pSuccess is Double because otherwise
expressions like (geometric p) would have an ambiguous type
such as (forall a.FloatConvert a Prob => a)
If we could add a (Num a) constraint and avoid disabling defaulting
when constraints from outside the standard library are used, then
we could default to Double.
Alternatively, if the hypothetical extension to multi-parameter
type-classes from the NamedDefaults proposal was ever proposed
and implemented, then we could do something like:
default FloatConvert a b => {a ~ b}
That would default to Prob instead. Hmm...
-}

0 comments on commit 93ba413

Please sign in to comment.