@@ -46,8 +46,10 @@ module Kore.AST.Kore
46
46
import Control.Comonad
47
47
import Control.Comonad.Trans.Cofree
48
48
( Cofree , CofreeF (.. ), ComonadCofree (.. ) )
49
+ import qualified Control.Comonad.Trans.Env as Env
49
50
import Control.DeepSeq
50
51
( NFData (.. ) )
52
+ import qualified Data.Bifunctor as Bifunctor
51
53
import Data.Deriving
52
54
( makeLiftCompare , makeLiftEq , makeLiftShowsPrec )
53
55
import Data.Functor.Classes
@@ -108,6 +110,7 @@ instance
108
110
Eq1 (UnifiedPattern domain variable )
109
111
where
110
112
liftEq = $ (makeLiftEq ''UnifiedPattern)
113
+ {-# INLINE liftEq #-}
111
114
112
115
instance
113
116
( Ord1 (Pattern Meta domain variable )
@@ -116,6 +119,7 @@ instance
116
119
Ord1 (UnifiedPattern domain variable )
117
120
where
118
121
liftCompare = $ (makeLiftCompare ''UnifiedPattern)
122
+ {-# INLINE liftCompare #-}
119
123
120
124
instance
121
125
( Show1 (Pattern Meta domain variable )
@@ -137,6 +141,7 @@ instance
137
141
salt `hashWithSalt` (0 :: Int ) `hashWithSalt` metaP
138
142
UnifiedObjectPattern objectP ->
139
143
salt `hashWithSalt` (1 :: Int ) `hashWithSalt` objectP
144
+ {-# INLINE hashWithSalt #-}
140
145
141
146
-- | View a 'Meta' or an 'Object' 'Pattern' as an 'UnifiedPattern'
142
147
asUnifiedPattern
@@ -194,7 +199,6 @@ deriving instance
194
199
) =>
195
200
Traversable (UnifiedPattern domain variable )
196
201
197
-
198
202
{- | The abstract syntax of Kore.
199
203
200
204
@KorePattern@ covers the 'Object' and 'Meta' levels of Kore, corresponding to
@@ -232,6 +236,7 @@ instance
232
236
(Recursive. project -> _ :< pat2)
233
237
=
234
238
liftEq eqWorker pat1 pat2
239
+ {-# INLINE (==) #-}
235
240
236
241
instance
237
242
( OrdMetaOrObject variable
@@ -246,6 +251,7 @@ instance
246
251
(Recursive. project -> _ :< pat2)
247
252
=
248
253
liftCompare compareWorker pat1 pat2
254
+ {-# INLINE compare #-}
249
255
250
256
deriving instance
251
257
( Show annotation
@@ -264,6 +270,7 @@ instance
264
270
Hashable (KorePattern domain variable annotation )
265
271
where
266
272
hashWithSalt salt (Recursive. project -> _ :< pat) = hashWithSalt salt pat
273
+ {-# INLINE hashWithSalt #-}
267
274
268
275
instance
269
276
( Functor domain
@@ -285,17 +292,109 @@ instance
285
292
Functor domain =>
286
293
Recursive (KorePattern domain variable annotation )
287
294
where
288
- project (KorePattern embedded) =
295
+ project = \ (KorePattern embedded) ->
289
296
case Recursive. project embedded of
290
297
Compose (Identity projected) -> KorePattern <$> projected
298
+ {-# INLINE project #-}
299
+
300
+ cata alg = \ (KorePattern fixed) ->
301
+ Recursive. cata
302
+ (\ (Compose (Identity base)) -> alg base)
303
+ fixed
304
+ {-# INLINE cata #-}
305
+
306
+ para alg = \ (KorePattern fixed) ->
307
+ Recursive. para
308
+ (\ (Compose (Identity base)) ->
309
+ alg (Bifunctor. first KorePattern <$> base)
310
+ )
311
+ fixed
312
+ {-# INLINE para #-}
313
+
314
+ gpara dist alg = \ (KorePattern fixed) ->
315
+ Recursive. gpara
316
+ (\ (Compose (Identity base)) -> Compose . Identity <$> dist base)
317
+ (\ (Compose (Identity base)) -> alg (Env. local KorePattern <$> base))
318
+ fixed
319
+ {-# INLINE gpara #-}
320
+
321
+ prepro pre alg = \ (KorePattern fixed) ->
322
+ Recursive. prepro
323
+ (\ (Compose (Identity base)) -> (Compose . Identity ) (pre base))
324
+ (\ (Compose (Identity base)) -> alg base)
325
+ fixed
326
+ {-# INLINE prepro #-}
327
+
328
+ gprepro dist pre alg = \ (KorePattern fixed) ->
329
+ Recursive. gprepro
330
+ (\ (Compose (Identity base)) -> Compose . Identity <$> dist base)
331
+ (\ (Compose (Identity base)) -> (Compose . Identity ) (pre base))
332
+ (\ (Compose (Identity base)) -> alg base)
333
+ fixed
334
+ {-# INLINE gprepro #-}
291
335
292
336
instance
293
337
Functor domain =>
294
338
Corecursive (KorePattern domain variable annotation )
295
339
where
296
- embed projected =
340
+ embed = \ projected ->
297
341
(KorePattern . Recursive. embed . Compose . Identity )
298
342
(getKorePattern <$> projected)
343
+ {-# INLINE embed #-}
344
+
345
+ ana coalg = KorePattern . ana0
346
+ where
347
+ ana0 =
348
+ Recursive. ana (Compose . Identity . coalg)
349
+ {-# INLINE ana #-}
350
+
351
+ apo coalg = KorePattern . apo0
352
+ where
353
+ apo0 =
354
+ Recursive. apo
355
+ (\ a ->
356
+ (Compose . Identity )
357
+ (Bifunctor. first getKorePattern <$> coalg a)
358
+ )
359
+ {-# INLINE apo #-}
360
+
361
+ postpro post coalg = KorePattern . postpro0
362
+ where
363
+ postpro0 =
364
+ Recursive. postpro
365
+ (\ (Compose (Identity base)) -> (Compose . Identity ) (post base))
366
+ (Compose . Identity . coalg)
367
+ {-# INLINE postpro #-}
368
+
369
+ gpostpro dist post coalg = KorePattern . gpostpro0
370
+ where
371
+ gpostpro0 =
372
+ Recursive. gpostpro
373
+ (Compose . Identity . dist . (<$>) (runIdentity . getCompose))
374
+ (\ (Compose (Identity base)) -> (Compose . Identity ) (post base))
375
+ (Compose . Identity . coalg)
376
+ {-# INLINE gpostpro #-}
377
+
378
+ instance
379
+ Functor domain =>
380
+ Comonad (KorePattern domain variable )
381
+ where
382
+ extract = \ (KorePattern fixed) -> extract fixed
383
+ {-# INLINE extract #-}
384
+ duplicate = \ (KorePattern fixed) -> KorePattern (extend KorePattern fixed)
385
+ {-# INLINE duplicate #-}
386
+ extend extending = \ (KorePattern fixed) ->
387
+ KorePattern (extend (extending . KorePattern ) fixed)
388
+ {-# INLINE extend #-}
389
+
390
+ instance
391
+ Functor domain =>
392
+ ComonadCofree
393
+ (UnifiedPattern domain variable )
394
+ (KorePattern domain variable )
395
+ where
396
+ unwrap = \ (KorePattern fixed) -> KorePattern <$> unwrap fixed
397
+ {-# INLINE unwrap #-}
299
398
300
399
-- | View an annotated 'Meta' or 'Object' 'Pattern' as a 'KorePattern'
301
400
asKorePattern
@@ -321,18 +420,6 @@ eraseAnnotations =
321
420
UnifiedMetaPattern _ -> UnifiedMeta Annotation. Null :< unified
322
421
UnifiedObjectPattern _ -> UnifiedObject Annotation. Null :< unified
323
422
324
- instance Functor dom => Comonad (KorePattern dom var ) where
325
- extract (KorePattern a) = extract a
326
- duplicate (KorePattern a) = KorePattern (extend KorePattern a)
327
- extend extending (KorePattern a) =
328
- KorePattern (extend (extending . KorePattern ) a)
329
-
330
- instance
331
- Functor domain =>
332
- ComonadCofree (UnifiedPattern domain variable ) (KorePattern domain variable )
333
- where
334
- unwrap (KorePattern a) = KorePattern <$> unwrap a
335
-
336
423
-- | View a 'Meta' or 'Object' 'Pattern' as a 'KorePattern'
337
424
asCommonKorePattern
338
425
:: MetaOrObject level
0 commit comments