curly is a surface syntax for Haskell that looks like the languages with
braces: fn, f(x, y) calls, x => e lambdas, Map<k, v> type arguments,
blocks instead of layout. A .curly file is translated to ordinary Haskell
source text, which GHC compiles; the semantics, the type system and the
libraries are Haskell's. The translation keeps every token on its line and
column, so GHC's errors point into the .curly file.
module Shapes (Shape(..), area, describe, totalArea)
import Data.List (sortOn)
data Shape
= Circle(Double)
| Rect { width: Double, height: Double }
deriving (Show, Eq)
fn area(s: Shape): Double = match (s) {
Circle(r) -> pi * r * r
Rect { width, height } -> width * height
}
fn describe<a>(label: String, x: a): String where Show<a> =
label ++ ": " ++ show(x)
fn totalArea(shapes: [Shape]): IO<Double> {
let sorted = sortOn(area, shapes)
mapM_(s => putStrLn(describe("shape", s)), sorted)
pure(sum(map(area, sorted)))
}
is translated to the equivalent of
{-# LANGUAGE ExplicitForAll, LexicalNegation, NamedFieldPuns #-}
module Shapes (Shape(..), area, describe, totalArea) where
import Data.List (sortOn)
data Shape
= Circle Double
| Rect { width :: Double, height :: Double }
deriving (Show, Eq)
area :: Shape -> Double
area s = case s of
Circle r -> pi * r * r
Rect { width, height } -> width * height
describe :: forall a. Show a => String -> a -> String
describe label x =
label ++ ": " ++ show x
totalArea :: [Shape] -> IO Double
totalArea shapes = do
let sorted = sortOn area shapes
mapM_ (\s -> putStrLn (describe "shape" s)) sorted
pure (sum (map area sorted))(The real output uses explicit braces and semicolons and has LINE and
COLUMN pragmas in it; it is meant for GHC, not for reading. curly-tools to-hs --pretty prints a version for readers.)
Early. The translator, the command line tool with a formatter, a small language server and a converter from Haskell exist and are tested against GHC 9.6.6, but the language covers only part of Haskell and nothing is released.
Supported: modules, imports and exports; let and fn bindings, type
signatures, inline annotations and where constraints, local definitions;
calls, placeholders, lambdas, blocks (do), match, if, list
comprehensions, operators, sections and fixity declarations, type
applications; patterns including records, views, bang and lazy patterns;
data (plain, record, GADT form, strict fields, kind signatures, deriving
clauses), newtype, type synonyms; type and data families and their
instances, role annotations; classes and instances with methods, functional
dependencies, associated types and default signatures; standalone deriving;
pattern synonyms; foreign and default declarations; types with forall,
contexts and promoted constructors; pragmas; Haddock comments; raw Haskell
blocks.
The extensions that change how a file is read are followed when the file
switches them on: Template Haskell and quasi-quotes, MagicHash and unboxed
tuples and sums, overloaded labels, implicit parameters, linear arrows, and
CPP directives between declarations, statements and alternatives.
Not supported: arrow notation, static forms and TransformListComp (they
go in a raw block [hs| ... |]), preprocessor directives inside an
expression, and a few smaller things.
docs/language.md has the list and the way around each.
curly's own diagnostics (syntax errors and lint findings) have messages in
English; the rule identifier in brackets, such as
[syntax/expected-declaration], is stable.
- docs/language.md: the language, construct by construct, next to the Haskell it stands for.
- docs/tooling.md:
curly checkandcurly build, the formatter (curly fmt), using curly in a cabal package and changing from one layout to the other (curly migrate), how positions are mapped, the lint, GHC's diagnostics with their types in curly notation and with hints (curly diag), the language server,curly-tools from-hsandto-hs. - editors/: attaching
curly-lspto an editor; a VS Code extension with a grammar for syntax highlighting. - examples/gen-dir and examples/pgmf: two small packages, one for each way of building with curly.
- examples/cabal-custom and
examples/cabal-hooks: templates for a package whose
setup program runs curly during
cabal build, withbuild-type: Customand withbuild-type: Hooks(cabal-install 3.14 or later).
GHC 9.6.6 and cabal 3.12 are the tested toolchain. curly-tools uses the
ghc library and builds with GHC 9.6 only. The Haskell that curly writes
can be tested with other compilers (see below).
cabal build all
cabal run curly -- check path/to/File.curly
cabal install curly curly-lsp
The commands:
curly check FILE... diagnostics, nothing is written
curly build [SOURCE-DIR...] translate a source tree to Haskell files
curly fmt [-w | --check] FILE|DIR... format curly source
curly diag -- COMMAND... run a build; GHC's types in curly notation, with hints
curly migrate --to=pgmf|gen [DIR...] change between the two project layouts
curly-lsp the language server
curly-tools from-hs FILE.hs... Haskell to curly
curly-tools to-hs [--pretty] FILE curly to Haskell, for GHC or for readers
Each prints its options with --help.
curly build --watch polls the modification times of the sources by default,
so that the tool depends on GHC's boot libraries only. With the cabal flag
fsnotify it uses file system notifications instead:
cabal build curly --constraint='curly +fsnotify'
cabal test all
| Suite | Package | What it does |
|---|---|---|
fast |
curly-core | lexer, parser, emitter golden files, invariant checker, lint, the formatter (golden files, its guarantees on every .curly file of the repository and on generated input), property tests, the code blocks of docs/, and the parser, the hints and the rewriting of types for GHC's diagnostics on output recorded from GHC 9.4.8, 9.6.6 and 9.12.4; no compiler involved |
cli |
curly | runs the curly executable: build, check, diag, fmt, migrate, the -pgmF entry point |
compile |
curly | runs GHC on the emitter's output: programs are compiled with -Wall -Werror and run, positions are compared with GHC's lexer, planted errors must be reported at the curly token, formatted programs must print what they printed before, the example packages are built |
lsp |
curly-lsp | the protocol, the position conversion, the outline, formatting, the diagnostics of a build, the proxy for haskell-language-server against a scripted stand-in, the server as a process (one test translates a file and runs GHC on it) |
heavy |
curly-tools | from-hs round trips over a hand-written corpus, the sources of this repository, the packages in cabal's download cache if there is one, and a set of negation cases that are compiled and run; to-hs --pretty on the test programs, compared with the plain translation by GHC's parser, some of them compiled and run |
compile needs ghc-9.6.6 (or the compiler named by CURLY_TEST_GHC) and
cabal on the PATH, lsp needs that compiler too, heavy needs ghc. With
CURLY_TEST_OTHER_GHCS="ghc-9.4.8 ghc-9.12.4" cabal test curly:test:compile
the test programs are also built and run with those compilers; the same
variable makes
The build-type: Hooks example needs a newer cabal than the tested
toolchain and a package from Hackage, so compile builds it only when it is
told what to use:
CURLY_TEST_HOOKS="cabal-3.14.2.0 ghc-9.12.4" cabal test curly:test:compile
names a cabal-install (3.14 or later) and a compiler that comes with the
Cabal library 3.14. cabal is run with --offline: Cabal-hooks has to be in
its store or its download cache already.
lsp talks to a real haskell-language-server only when it is told which:
CURLY_TEST_HLS="haskell-language-server-9.12.4 ghc-9.12.4 cabal-3.14.2.0" cabal test curly-lsp:test:lsp
names a haskell-language-server, the compiler it was built for and a cabal.
The test opens a copy of examples/gen-dir through curly-lsp --hls and
checks a planted type error, hover, definitions, references and completion
at the positions of the .curly files; it prints how long the answers took
and how much memory the language server used. It needs no network.
Every compiler, build tool and generated program a suite starts has a time limit and is killed with its process group when it is reached, so a hang fails the test; the generated programs also run with a heap limit.
The .curly files of the repository and the curly code blocks of docs/
are kept formatted, and fast fails when curly fmt would change one. The
few test inputs whose odd layout is the point are listed in
curly-core/test/FormatTests.hs.
Golden files live in curly-core/test/golden; run the suite with
--test-options=--accept to update them after an intended change.
curly-core/ library: lexer, syntax tree, parser, emitter, invariant
checker, lint; test-suite `fast`
curly/ the `curly` executable; test-suites `cli` and `compile`
curly-lsp/ the `curly-lsp` language server; test-suite `lsp`
curly-tools/ `curly-tools`: tools that need GHC's parser (`from-hs`);
test-suite `heavy`
editors/ editor configuration for curly-lsp, the VS Code extension
examples/ minimal packages built with curly, one for each way
docs/ language guide and tooling guide