~ubuntu-branches/ubuntu/raring/agda/raring-proposed

« back to all changes in this revision

Viewing changes to src/full/Agda/Syntax/Strict.hs

  • Committer: Bazaar Package Importer
  • Author(s): Iain Lane
  • Date: 2009-07-20 19:49:41 UTC
  • Revision ID: james.westby@ubuntu.com-20090720194941-hcjy91vrn16csh7d
Tags: upstream-2.2.4+dfsg
ImportĀ upstreamĀ versionĀ 2.2.4+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
{-# LANGUAGE CPP #-}
 
2
 
 
3
module Agda.Syntax.Strict where
 
4
 
 
5
import Data.Generics
 
6
 
 
7
import Agda.Syntax.Common
 
8
import Agda.Syntax.Internal
 
9
import Agda.Syntax.Parser.Tokens
 
10
import qualified Agda.Syntax.Concrete as C
 
11
import qualified Agda.Syntax.Concrete.Definitions as C
 
12
 
 
13
#include "../undefined.h"
 
14
import Agda.Utils.Impossible
 
15
 
 
16
class Strict a where
 
17
    force :: a -> Int
 
18
 
 
19
instance Strict Term where
 
20
    force t = case t of
 
21
        Var _ ts   -> force ts
 
22
        Def _ ts   -> force ts
 
23
        Con _ ts   -> force ts
 
24
        Lam _ t    -> force t
 
25
        Lit _      -> 0
 
26
        Pi a b     -> force (a,b)
 
27
        Fun a b    -> force (a,b)
 
28
        Sort s     -> force s
 
29
        MetaV _ ts -> force ts
 
30
 
 
31
instance Strict Type where
 
32
    force (El s t) = force (s,t)
 
33
 
 
34
instance Strict Sort where
 
35
    force s = case s of
 
36
        Type n    -> fromIntegral n
 
37
        Prop      -> 0
 
38
        Lub s1 s2 -> force (s1,s2)
 
39
        Suc s     -> force s
 
40
        MetaS _   -> 0
 
41
 
 
42
instance Strict ClauseBody where
 
43
    force (Body t)   = force t
 
44
    force (Bind b)   = force b
 
45
    force (NoBind b) = force b
 
46
    force  NoBody    = 0
 
47
 
 
48
instance Strict C.Expr where
 
49
    force e = everything (+) (const 1) e
 
50
 
 
51
instance Strict C.Declaration where
 
52
    force e = everything (+) (const 1) e
 
53
 
 
54
instance Strict C.Pragma where
 
55
    force e = everything (+) (const 1) e
 
56
 
 
57
instance Strict C.NiceDeclaration where
 
58
    force d = everything (+) (const 1) d
 
59
 
 
60
instance (Strict a, Strict b) => Strict (a,b) where
 
61
    force (x,y) = force x + force y
 
62
 
 
63
instance Strict a => Strict (Arg a) where
 
64
    force = force . unArg
 
65
 
 
66
instance Strict a => Strict [a] where
 
67
    force = sum . map force
 
68
 
 
69
instance Strict a => Strict (Abs a) where
 
70
    force = force . absBody
 
71
 
 
72
instance Strict Token where
 
73
  -- TODO: This is just a dummy instance. Why can't we just use the
 
74
  -- NFData derivation provided by Drift?
 
75
  force = (`seq` 0)
 
76
 
 
77
infixr 0 $!!
 
78
 
 
79
($!!) :: Strict a => (a -> b) -> a -> b
 
80
f $!! x = force x `seq` f x
 
81
 
 
82
strict :: Strict a => a -> a
 
83
strict x = id $!! x
 
84