The clafer package


Clafer is a general purpose, lightweight, structural modeling language developed at GSD Lab, University of Waterloo, and MODELS group at IT University of Copenhagen. Lightweight modeling aims at improving the understanding of the problem domain in the early stages of software development and determining the requirements with fewer defects. Clafer's goal is to make modeling more accessible to a wider range of users and domains. The tool provides a reference language implementation. It translates models to other formats (e.g. Alloy, XML) to allow for reasoning with existing tools.

[Skip to ReadMe]


Versions0.3.5,, 0.3.6,, 0.3.7, 0.3.8, 0.3.9, 0.3.9, 0.3.10, 0.4.0, 0.4.1, 0.4.2,, 0.4.3, 0.4.4, 0.4.5
Dependenciesaeson (>=, array (>=, base (>= && <5), bytestring (>=, clafer (==0.3.9), cmdargs (>=0.10.7), containers (>=, data-stringmap (>=, directory (>=, executable-path (>=0.0.3), filepath (>=, HaXml (>=1.24), HTTP (>=4000.2.10), json-builder (>=0.3), lens (>=4.7), lens-aeson (>=, mtl (>=, network (>=2.6), network-uri (>=2.6), parsec (>=3.1.3), process (>=, split (>=0.2.2), string-conversions (>=, text (>=, transformers (>= [details]
AuthorKacper Bak, Jimmy Liang, Michal Antkiewicz, Ed Zulkoski, Luke Michael Brown, Paulius Juodisius, Rafael Olaechea
MaintainerMichal Antkiewicz <>
Home page
Source repositoryhead: git clone git://
UploadedFri Mar 6 17:18:38 UTC 2015 by mantkiew




Maintainers' corner

For package maintainers and hackage trustees

Readme for clafer-0.3.9

Clafer ====== v0.3.9 Clafer is a general-purpose lightweight structural modeling language developed by GSD Lab, University of Waterloo, and MODELS group at IT University of Copenhagen. Clafer can be used for modeling of static hierarchical structures but has no support for modeling the change of the structures over time (behavior). The main goal of Clafer is to make modeling more accessible to a wider range of users and domains. There are many possible applications of Clafer; however, three are prominent:

  1. Product-Line Modeling - aims at representing and managing commonality and variability of assets in product lines and creating and verifying product configurations. Clafer naturally supports multi-staged configuration.
  2. Multi-Objective Product Optimization - aims at finding a set of products in a given product line that are optimal with respect to a set of objectives. Clafer multi-objective optimizer generates a Pareto front of optimal product configurations.
  3. Domain Modeling - aims at improving the understanding of the problem domain in the early stages of software development and determining the requirements with fewer defects. This is also known as Concept Modeling or Ontology Modeling. Clafer Compiler =============== Clafer compiler provides a reference language implementation. It translates models in Clafer to other formats (e.g., Alloy, XML, Python, JS, HTML, DOT) to allow for reasoning and processing with existing tools (Alloy Analyzer, Choco3, and Z3 SMT solver). Currently, the compiler is used by

Dependencies for running

Regardless of the installation method, the following are Optional:

Installation from binaries

Binary distributions of the release 0.3.9 of Clafer Tools for Windows, Mac, and Linux, can be downloaded from Clafer Tools - Binary Distributions.

  1. download the binaries and unpack <target directory> of your choice
  2. add the <target directory> to your system path so that the executables can be found

Installation from Hackage


  1. cabal update
  2. cabal install clafer
  3. cd <cabal's lib or share folder> (C:\Users\<user>\AppData\Roaming\cabal\x86_64-windows-ghc-7.8.3\clafer-0.3.9 on Windows or .cabal/share/x86_64-linux-ghc-7.8.3/clafer-0.3.9/ on Linux)
  4. to automatically download Alloy jars
    • execute make in tools

Installation from the source code


Important: Branches must correspond

All related projects are following the simultaneous release model. The branch master contains releases, whereas the branch develop contains code under development. When building the tools, the branches should match. Releases from branches 'masterare guaranteed to work well together. Development versions from branchesdevelop` should work well together but this might not always be the case.


  1. install the dependencies
  2. open the command line terminal. On Windows, open MSYS2 terminal.
  3. in some <source directory> of your choice, execute
    • git clone git://
  4. in <source directory>/clafer, execute
    • cabal update
    • make init
    • make


  1. Execute
    • make install to=<target directory>


On Windows, use / with the make command instead of \. Integration with Sublime Text 2/3 --------------------------------- See ClaferToolsST Integration with VIM -------------------- See clafer-vim Usage ===== Clafer Compiler --------------- (As printed by clafer --help)

Clafer 0.3.9

clafer [OPTIONS] [FILE]

Common flags:
  -m --mode=CLAFERMODE                    Generated output type. Available
                                          CLAFERMODEs are: 'alloy' (Alloy 4.1);
                                          'alloy42' (default, Alloy 4.2); 'xml'
                                          (intermediate representation of
                                          Clafer model); 'clafer' (analyzed and
                                          desugared clafer model); 'html'
                                          (original model in HTML); 'graph'
                                          (graphical representation written in
                                          DOT language); 'cvlgraph' (cvl
                                          notation representation written in
                                          DOT language); 'python' (generates IR
                                          in python); 'choco' (Choco constraint
                                          programming solver). Multiple modes
                                          can be specified at the same time,
                                          e.g., '-m alloy -m html'.
  -o --console-output                     Output code on console.
  -i --flatten-inheritance                Flatten inheritance ('alloy' and
                                          'alloy42' modes only).
     --timeout-analysis=INT               Timeout for analysis.
  -l --no-layout                          Don't resolve off-side rule layout.
     --nl --new-layout                    Use new fast layout resolver
  -c --check-duplicates                   Check duplicated clafer names in
                                          the entire model.
  -f --skip-resolver                      Skip name resolution.
  -k --keep-unused                        Keep uninstantated abstract clafers
                                          ('alloy' and 'alloy42' modes only).
  -s --no-stats                           Don't print statistics.
     --schema                             Show Clafer IR (intermediate
                                          representation) XML schema.
  -v --validate                           Validate outputs of all modes. Uses
                                          'tools/XsdCheck.class' for XML,
                                          'tools/alloy4.jar' and
                                          'tools/alloy4.2.jar' for Alloy
                                          models, and Clafer translator for
                                          desugared Clafer models. Use
                                          '--tooldir' to override the default
                                          location of these tools.
     --nr --noalloyruncommand             For usage with partial instances:
                                          Don't generate the alloy 'run show
                                          for ... ' command, and rename @.ref
                                          with unique names  ('alloy' and
                                          'alloy42' modes only).
     --tooldir=DIR                        Specify the tools directory
                                          ('validate' only). Default: 'tools/'.
  -a --alloy-mapping                      Generate mapping to Alloy source
                                          code ('alloy' and 'alloy42' modes
     --self-contained                     Generate a self-contained html
                                          document ('html' mode only).
     --add-graph                          Add a graph to the generated html
                                          model ('html' mode only). Requires
                                          the "dot" executable to be on the
                                          system path.
     --sr --show-references               Whether the links for references
                                          should be rendered. ('html' and
                                          'graph' modes only).
     --add-comments                       Include comments from the source
                                          file in the html output ('html' mode
  -e --ecore2clafer                       Translate an ECore model into
     --ss=SCOPESTRATEGY --scope-strategy  Use scope computation strategy:
                                          none or simple (default).
     --check-afm --afm                    Throws an error if the cardinality
                                          of any of the clafers is above 1.
     --sg --skip-goals                    Skip generation of Alloy code for
                                          goals. Useful for all tools working
                                          with standard Alloy.
     --meta-data                          Generate a 'fully qualified
                                          name'-'unique ID' map ('.cfr-map').
                                          In Alloy, Alloy42, and Choco modes,
                                          generate the scopes map
  -? --help                               Display help message
  -V --version                            Print version information
     --numeric-version                    Print just the version number

The dependencies among the command line arguments are described on the model wiki. Multiple modes can be used at the same time. For example, clafer model.cfr -m alloy -m xml -m html -m graph --self-contained --show-references --no-stats The mode -m alloy42 is only the default mode if no other modes are given. When other modes are given, the mode -m alloy42 must be added explicitly if needed. Additionally, [OPTIONS] can also be specified directly in the model file by inserting the following compiler directive as the first line of the file:


for example

//# --keep-unused -m=alloy

Options given at command line override the options given in the file using //# which, in turn, override the defaults.

Using compiler directives

Compiler directives are comments of the form

//# <directive name>

The following directives are markers of locations in the input files for different purposes: