7
Nel codice che definisce una funzione, v'è uno strano "pattern match" (cradleRootDir -> projdir)
pattern partita in argomento di funzione in Haskell
Immagino che si intende applicare la funzione inline e si lega il risultato al nome projdir
.
Qual è il nome di questo costrutto?
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
Il costruttore
data Cradle = Cradle {
cradleCurrentDir :: FilePath
, cradleRootDir :: FilePath
, cradleCabalFile :: Maybe FilePath
, cradlePkgDbStack :: [GhcPkgDb]
} deriving (Eq, Show)
Questo è un modello vista. Vedi [questa domanda] (http://stackoverflow.com/q/20766841/2751851) per alcuni esempi interessanti. – duplode