8

In the code defining a function, there is a strange "pattern match" (cradleRootDir -> projdir)

I guess that is meant to apply the function inline and binds the result to the name projdir.

What is the name of that construct ?

withGhcModEnv' :: (IOish m, GmOut m) => (FilePath -> (Cradle -> m a) -> m a) -> FilePath -> Options -> ((GhcModEnv, GhcModLog) -> m a) -> m a
withGhcModEnv' withCradle dir opts f =
    withCradle dir $ \crdl ->
      withCradleRootDir crdl $
        f (GhcModEnv opts crdl, undefined)
 where
   withCradleRootDir (cradleRootDir -> projdir) a = do
       cdir <- liftIO $ getCurrentDirectory
       eq <- liftIO $ pathsEqual projdir cdir
       if not eq
          then throw $ GMEWrongWorkingDirectory projdir cdir
          else a

The constructor

data Cradle = Cradle {
    cradleCurrentDir :: FilePath
  , cradleRootDir    :: FilePath
  , cradleCabalFile  :: Maybe FilePath
  , cradlePkgDbStack  :: [GhcPkgDb]
  } deriving (Eq, Show)
1
  • 3
    That is a view pattern. See this question for some interesting examples. Commented Oct 27, 2015 at 11:53

1 Answer 1

7

It's using View Patterns

Evaluation To match a value v against a pattern (expr -> pat), evaluate (expr v) and match the result against pat.

See cabal file

Default-Extensions:   ScopedTypeVariables, RecordWildCards, NamedFieldPuns,
                      ConstraintKinds, FlexibleContexts,
                      DataKinds, KindSignatures, TypeOperators, ViewPatterns
                                                                ^^^^^^^^^^^^
                                                                |  |  |  | |
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.