File: Types.hs

package info (click to toggle)
bali-phy 4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 15,392 kB
  • sloc: cpp: 120,442; xml: 13,966; haskell: 9,975; python: 2,936; yacc: 1,328; perl: 1,169; lex: 912; sh: 343; makefile: 26
file content (42 lines) | stat: -rw-r--r-- 1,254 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
{-# LANGUAGE NoImplicitPrelude #-}
module Data.Floating.Types where

foreign import bpcall "Num:" intToDouble :: Int -> Double
foreign import bpcall "Num:" integerToDouble :: Integer -> Double

class FloatConvert a b where
    toFloating :: a -> b

instance FloatConvert Integer Double where
    toFloating  = integerToDouble

instance FloatConvert Int     Double where
    toFloating = intToDouble

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...

-}