@@ -1,6 +1,11 @@
11{-# OPTIONS_GHC -Wall #-}
22{-# LANGUAGE OverloadedStrings #-}
3−module Validate (Result, validate) where
3+module Validate
4+ ( Result
5+ , validate
6+ )
7+ where
8+
49
510import Control.Applicative (liftA2)
611import Control.Monad (forM_)
@@ -9,7 +14,6 @@ import Data.Text (Text)
914
1015import qualified AST.Expression.Source as Src
1116import qualified AST.Expression.Valid as Valid
12−import qualified AST.Pattern as Pattern
1317import qualified AST.Type as Type
1418import qualified Elm.Name as N
1519import qualified Reporting.Annotation as A
@@ -19,7 +23,6 @@ import qualified Reporting.Result as Result
1923
2024
2125
22−
2326-- VALIDATE
2427
2528
@@ -260,22 +263,23 @@ definitions sourceDefs =
260263
261264 A.A annRegion (Src.Annotate annotationName tipe) : otherDefs ->
262265 case otherDefs of
263− A.A defRegion (Src.Define name args expr) : otherOtherDefs | name == annotationName ->
264− (:)
265− <$> validateDefinition (R.merge annRegion defRegion) name args expr (Just tipe)
266− <*> definitions otherOtherDefs
266+ A.A defRegion (Src.Define name@(A.A _ definitionName) args expr) : otherOtherDefs
267+ | definitionName == annotationName ->
268+ (:)
269+ <$> validateDefinition (R.merge annRegion defRegion) name args expr (Just tipe)
270+ <*> definitions otherOtherDefs
267271
268272 _ ->
269273 Result.throw annRegion (Error.TypeWithoutDefinition annotationName)
270274
271275
272−validateDefinition :: R.Region -> Text -> [Pattern.Raw] -> Src.Expr -> Maybe Type.Raw -> Result w Valid.Def
276+validateDefinition :: R.Region -> A.Located Text -> [Src.Pattern] -> Src.Expr -> Maybe Type.Raw -> Result w Valid.Def
273277validateDefinition region name args expr maybeType =
274278 do validExpr <- expression expr
275279 return $ Valid.Define region name args validExpr maybeType
276280
277281
278−validateDestruct :: R.Region -> Pattern.Raw -> Src.Expr -> Result w Valid.Def
282+validateDestruct :: R.Region -> Src.Pattern -> Src.Expr -> Result w Valid.Def
279283validateDestruct region pattern expr =
280284 Valid.Destruct region pattern <$> expression expr
281285