简体   繁体   中英

Is START_FILE a GHC pragma?

Who could provide information regarding START_FILE pragma?

The is no word about START_FILE in GHC Pragmas Documentation . Nevertheless it seems to be widely used [1] , [2] , [3] .

Unfortunately ghc 8.2.2 does not compile following code [1] .

{-# START_FILE main.hs #-}
main = readFile "file.txt" >>= putStr

{-# START_FILE file.txt #-}
Hello, world!

No, this is an extension specific to School of Haskell Markdown . It's used to provide several "files" in a single Markdown code block.

It's not "widely used" outside of School of Haskell for that reason. When reading such code snippets, simple treat everything after a START_FILE pragma as if it was in a file with the name indicated as the parameter (if it indicates a format like BASE64 you need to put the decoded bytes into the file instead).

This pragma is used by stack templates. You can specify multiple files inside single file with extension .hsfiles by separating files with {-# START_FILE #-} pragma.

stack new PACKAGE_NAME myfiles.hsfiles will create those files (and all directories automatically) according to your layout, if myfiles.hsfiles contains:

{-# START_FILE {{name}}.cabal #-}
name:                {{name}}
version:             0.1.0.0

or

{-# START_FILE package.yaml #-}
name:                {{name}}
version:             0.1.0.0

See some examples in this repository:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM