never executed always true always false
    1 {-# LANGUAGE DataKinds #-}
    2 {-# LANGUAGE GADTs #-}
    3 module ElmFormat.AST.PatternMatching where
    4 
    5 import ElmFormat.AST.Shared
    6 import AST.V0_16
    7 import AST.Structure
    8 import Reporting.Annotation (Located(A))
    9 import Data.Indexed as I
   10 
   11 
   12 {-| Takes a list of patterns and matches them agains a type,
   13 extracting the types of each of the patterns
   14 and the return type of a function that has that list of patterns as its parameters.
   15 
   16 TODO: retain all comments in the output
   17 TODO: make complete function so it doesn't crash on invalid source files
   18 -}
   19 matchType ::
   20     List (C1 'BeforeTerm (ASTNS Located ns 'PatternNK))
   21     -> ASTNS Located ns 'TypeNK
   22     -> ( List (C1 'BeforeTerm (ASTNS Located ns 'PatternNK), ASTNS Located ns 'TypeNK)
   23        , ASTNS Located ns 'TypeNK
   24        )
   25 matchType [] typ = ( [], typ )
   26 matchType (pat : restPat) (I.Fix (A region (FunctionType (C eol typ) restTyp multiline))) =
   27     let
   28         nextTyp =
   29             case toCommentedList restTyp of
   30                 [ (C _ single) ] -> single
   31                 ( (C (_, _, eol2) first) : rest ) -> I.Fix $ A region $ FunctionType (C eol2 first) (Sequence rest) multiline
   32 
   33         ( pats, retType ) =
   34             matchType restPat nextTyp
   35     in
   36     ( (pat, typ) : pats, retType )