Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is package.yaml & stack.yaml & Setup.hs & the-project-name.cabal files?

I find that, when I use the stack new the-project-name new-template command, many files is generated into a new directory. and I notice the following 4 special files:

package.yaml
stack.yaml
Setup.hs
the-project-name.cabal

These 4 files seems intending to provide meta data for package-managing software, but they looks confusing, I mean, why there are 4 of them, why not just one, and what's the difference between them?

like image 776
luochen1990 Avatar asked Jun 16 '18 16:06

luochen1990


People also ask

What is a YAML file used for?

What is YAML used for? One of the most common uses for YAML is to create configuration files. It's recommended that configuration files be written in YAML rather than JSON, even though they can be used interchangeably in most cases, because YAML has better readability and is more user-friendly.

What is YAML file in Java?

YAML stands for YAML Ain't Markup Language, it is a data-serialization language most commonly used for specifying project configuration details. The main motivation behind YAML is that it is designed to be in a format which is humanly friendly.

Is YAML and yml same?

Yaml files created with yaml and yml file extensions, Both are the same in interpretation and syntax. Nowadays, there is no OS system level enforcement to have 3 letters in extensions. Most of the yaml users are using . yaml as their preferred choice.

What is YAML file extension?

A YAML file is a text document that contains data formatted using YAML (YAML Ain't Markup Language), a human-readable data format used for data serialization. It is used for reading and writing data independent of a specific programming language.


1 Answers

Those configuration files serve different purposes. It's not clear what is better: have single all-inclusive configuration file or different files for different build tools and different goals.

the-project-name.cabal

This file contains description of your package. Like, list of modules, library dependencies, compiler options, project metadata (author's name, package version, etc.). This description is specified in special for cabal format.

package.yaml

This configuration file is used by hpack tool. It allows to specify the same things you specify in .cabal file. But in YAML format instead of custom cabal format. Also it adds some features over cabal. If you don't want to dive into hpack for now you can safely delete package.yaml file. Note, that .cabal file is generated by hpack from package.yaml file so you mustn't edit .cabal file if you're using hpack.

stack.yaml

Configuration for stack build tool. Add some extra configuration parameters. Most important: name of the LTS resolver.

Setup.hs

Used to add some build-hooks. In almost all cases you can delete this file as well. But I can give you real-life usage example of this file from our work.

We're writing service where different nodes should communicate using Protocol Buffers format. TL;DR pretty good format for describing message specifications. Those messages are written in files with extension .proto. But we actually want to work with Haskell types. There exist library proto-lens which can take files written in Protocol Buffers format, parse those files and generate Haskell modules containing data types representing those messages. This file generation should be done before project compilation. So this process is described in Setup.hs file.

like image 191
Shersh Avatar answered Sep 20 '22 18:09

Shersh