File: dynamic004.hs

package info (click to toggle)
ghc 9.6.6-4
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 158,216 kB
  • sloc: haskell: 648,228; ansic: 81,656; cpp: 11,808; javascript: 8,444; sh: 5,831; fortran: 3,527; python: 3,277; asm: 2,523; makefile: 2,298; yacc: 1,570; lisp: 532; xml: 196; perl: 145; csh: 2
file content (35 lines) | stat: -rw-r--r-- 983 bytes parent folder | download | duplicates (5)
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
module Main where

import Data.Typeable
import GHC.Fingerprint
import Text.Printf

f :: Typeable a => Int -> a -> [TypeRep]
f 0 a = []
f n a = typeOf a : f (n-1) [a]

-- pointwise compare 1000x1001 TypeReps, there should be exactly 1000 equalities
-- (can be used as a benchmark)
main = print $ length [ t1 | t1 <- f 1000 (), t2 <- f 1001 (), t1 == t2 ]

{-
 DEBUGGING code to help find bugs in the TypeRep implementation when
 this test fails:

 where
   g (x:xs) (y:ys)
     | x == y = g xs ys
     | otherwise = do
         print x
         case x of
           TypeRep f1 (TyCon f2 _ _ _) [TypeRep f3 _ _] ->
              printf "f1: %s\nf2: %s\nf3: %s\n" (show_fp f1) (show_fp f2) (show_fp f3)
         case y of
           TypeRep f1 (TyCon f2 _ _ _) [TypeRep f3 _ _] ->
              printf "f1: %s\nf2: %s\nf3: %s\n" (show_fp f1) (show_fp f2) (show_fp f3)
   g _ _ = return ()

   show_fp :: Fingerprint -> String
   show_fp (Fingerprint h l) =
       printf "%x %x" h l
-}