never executed always true always false
    1 {-# LANGUAGE DataKinds #-}
    2 module AST.Listing where
    3 
    4 import AST.V0_16
    5 import Data.Map.Strict
    6 
    7 
    8 -- | A listing of values. Something like (a,b,c) or (..) or (a,b,..)
    9 data Listing a
   10     = ExplicitListing a Bool
   11     | OpenListing (C2 'BeforeTerm 'AfterTerm ())
   12     | ClosedListing
   13     deriving (Eq, Ord, Show) -- TODO: is Ord needed?
   14 
   15 mergeListing :: (a -> a -> a) -> Listing a -> Listing a -> Listing a
   16 mergeListing merge left right =
   17     case (left, right) of
   18         (ClosedListing, ClosedListing) -> ClosedListing
   19         (ClosedListing, OpenListing comments) -> OpenListing comments
   20         (OpenListing comments, ClosedListing) -> OpenListing comments
   21         (OpenListing (C (pre1, post1) ()), OpenListing (C (pre2, post2) ())) -> OpenListing (C (pre1 ++ pre2, post1 ++ post2) ())
   22         (ClosedListing, ExplicitListing a multiline) -> ExplicitListing a multiline
   23         (ExplicitListing a multiline, ClosedListing) -> ExplicitListing a multiline
   24         (OpenListing comments, ExplicitListing _a _multiline) -> OpenListing comments
   25         (ExplicitListing _a _multiline, OpenListing comments) -> OpenListing comments
   26         (ExplicitListing a multiline1, ExplicitListing b multiline2) -> ExplicitListing (merge a b) (multiline1 || multiline2)
   27 
   28 
   29 type CommentedMap k v =
   30     Map k (C2 'BeforeTerm 'AfterTerm v)
   31 
   32 mergeCommentedMap :: Ord k => (v -> v -> v) -> CommentedMap k v -> CommentedMap k v -> CommentedMap k v
   33 mergeCommentedMap merge left right =
   34     let
   35         merge' (C (pre1, post1) a) (C (pre2, post2) b) =
   36             C (pre1 ++ pre2, post1 ++ post2) (merge a b)
   37     in
   38     unionWith merge' left right
   39 
   40 
   41 -- | A value that can be imported or exported
   42 data Value
   43     = Value !LowercaseIdentifier
   44     | OpValue SymbolIdentifier
   45     | Union (C1 'AfterTerm UppercaseIdentifier) (Listing (CommentedMap UppercaseIdentifier ()))
   46     deriving (Eq, Ord, Show) -- TODO: is Ord needed?