File: Instances.hs

package info (click to toggle)
haskell-flexible-defaults 0.0.3-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 72 kB
  • sloc: haskell: 297; makefile: 2
file content (65 lines) | stat: -rwxr-xr-x 1,062 bytes parent folder | download | duplicates (4)
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
{-# LANGUAGE TemplateHaskell, FlexibleInstances #-}
{-# OPTIONS_GHC -ddump-splices -fno-warn-orphans -fno-warn-missing-signatures #-}
module Instances where

import Class

$(defaultsTest
    [d|
        instance DefaultsTest Int where
            qux = toInteger
    |]
 )

$(defaultsTest
    [d|
        instance DefaultsTest [Char] where
            foo = id
    |]
 )

$(defaultsTest
    [d|
        instance DefaultsTest Integer where
    |]
 )

$(defaultsTest
    [d|
        instance DefaultsTest Float where
            bar = round
    |]
 )

$(defaultsTest
    [d|
        instance DefaultsTest Double where
            quux = (>2147483647) . abs
    |]
 )

$(defaultsTest
    [d|
        instance DefaultsTest Bool where
            foo True  = "0"
            foo False = "1"

            baz = (||)
    |]
 )

test x =
    ( foo x
    , bar x
    , qux x
    , quux x
    )

tests =
    [ test (1 :: Int)
    , test "123"
    , test (1000000000000000000000000000 :: Integer)
    , test (1e10 :: Float)
    , test (1e30 :: Double)
    , test True
    ]