never executed always true always false
1 module Conjure.Language.RepresentationOf where
2
3 -- conjure
4
5 import Conjure.Language.Domain
6 import Conjure.Language.Type (TypeCheckerMode)
7 import Conjure.Prelude
8
9 class RepresentationOf a where
10 representationTreeOf ::
11 (MonadFailDoc m, ?typeCheckerMode :: TypeCheckerMode) =>
12 a ->
13 m (Tree (Maybe HasRepresentation))
14
15 representationOf :: (RepresentationOf a, MonadFailDoc m, ?typeCheckerMode :: TypeCheckerMode) => a -> m HasRepresentation
16 representationOf a =
17 case representationTreeOf a of
18 Nothing -> failDoc "doesn't seem to have a representation tree"
19 Just tree ->
20 case rootLabel tree of
21 Nothing -> failDoc "doesn't seem to have a representation"
22 Just NoRepresentation -> failDoc "doesn't seem to have a representation"
23 Just r -> return r
24
25 hasRepresentation :: (RepresentationOf a, MonadFailDoc m, ?typeCheckerMode :: TypeCheckerMode) => a -> m ()
26 hasRepresentation x =
27 case representationTreeOf x of
28 Nothing -> failDoc "doesn't seem to have a representation"
29 Just _ -> return ()
30
31 sameRepresentation :: (RepresentationOf a, MonadFailDoc m, ?typeCheckerMode :: TypeCheckerMode) => a -> a -> m ()
32 sameRepresentation x y =
33 case (representationOf x, representationOf y) of
34 (Just rx, Just ry) | rx == ry -> return ()
35 _ -> failDoc "doesn't seem to have the same representation"
36
37 sameRepresentationTree :: (RepresentationOf a, MonadFailDoc m, ?typeCheckerMode :: TypeCheckerMode) => a -> a -> m ()
38 sameRepresentationTree x y = do
39 xTree <- representationTreeOf x
40 yTree <- representationTreeOf y
41 unless (xTree == yTree)
42 $ failDoc "doesn't seem to have the same representation tree"