-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathAmalgamate.hs
66 lines (53 loc) · 2.21 KB
/
Amalgamate.hs
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
66
{- |
Module : ./Common/Amalgamate.hs
Description : data types for amalgamability options and analysis
Copyright : (c) Christian Maeder, Uni Bremen 2004
License : GPLv2 or higher, see LICENSE.txt
Maintainer : till@informatik.uni-bremen.de
Stability : provisional
Portability : portable
Data types for amalgamability options and analysis
-}
module Common.Amalgamate where
import Data.Char
import Data.List
{- | 'CASLAmalgOpt' describes the options for CASL amalgamability analysis
algorithms -}
data CASLAmalgOpt = Sharing -- ^ perform the sharing checks
| ColimitThinness -- ^ perform colimit thinness check (implies Sharing)
| Cell -- ^ perform cell condition check (implies Sharing)
| NoAnalysis -- ^ dummy option to indicate empty option string
{- | Amalgamability analysis might be undecidable, so we need
a special type for the result of ensures_amalgamability -}
data Amalgamates = Amalgamates
| NoAmalgamation String -- ^ failure description
| DontKnow String {- ^ the reason for unknown status
The default value for 'DontKnow' amalgamability result -}
defaultDontKnow :: Amalgamates
defaultDontKnow = DontKnow "Unable to assert that amalgamability is ensured"
instance Show CASLAmalgOpt where
show o = case o of
Sharing -> "sharing"
ColimitThinness -> "colimit-thinness"
Cell -> "cell"
NoAnalysis -> "none"
instance Read CASLAmalgOpt where
readsPrec _ = readShow caslAmalgOpts
-- | test all possible values, ignore leading space
readShowAux :: [(String, a)] -> ReadS a
readShowAux l s =
let s' = dropWhile isSpace s
f _ [] = Nothing
f g' (x : xs) = case g' x of
Just res -> Just (x, res)
_ -> f g' xs
g (p, _) = stripPrefix p s'
in case f g l of
Nothing -> []
Just ((_, t), s'') -> [(t, s'')]
-- | input all possible values and read one as it is shown
readShow :: Show a => [a] -> ReadS a
readShow = readShowAux . map ( \ o -> (show o, o))
-- | possible CASL amalgamability options
caslAmalgOpts :: [CASLAmalgOpt]
caslAmalgOpts = [NoAnalysis, Sharing, Cell, ColimitThinness]