]> Git — Sourcephile - haskell/symantic.git/blob - symantic/symantic.cabal
Fix Dim.
[haskell/symantic.git] / symantic / symantic.cabal
1 author: Julien Moutinho <julm+symantic@autogeree.net>
2 bug-reports: Julien Moutinho <julm+symantic@autogeree.net>
3 build-type: Simple
4 cabal-version: >= 1.24
5 category: Language
6 description:
7 __Description__
8 .
9 This is an experimental library for composing, parsing, typing, compiling, transforming and interpreting
10 a custom DSL (Domain-Specific Language) expressing
11 a subset of GHC's Haskell type system:
12 .
13 * /first class functions/ (aka. /lambdas/),
14 * chosen /monomorphic types/ (like 'Bool' or 'Maybe'),
15 * chosen /rank-1 polymorphic types/ (like @(@'Maybe'@ a)@),
16 * chosen /type class instances/,
17 * chosen /type family instances/,
18 * and chosen /type constraints/;
19 .
20 where "chosen X" means declared in Haskell
21 and selected when composing the DSL.
22 .
23 In particular, this library is currently not able to:
24 .
25 * do /type inferencing/ for the argument of /lambdas/
26 (they must all be explicitely annotated, aka. /Church-style/),
27 * do /pattern matching/ (aka. /case/) (but /Church-encoding/ functions are often enough),
28 * do /rank-N polymorphic types/ (aka. /non-prenex forall/, like @(forall s. ST s a) -> a@).
29 .
30 And by itself, the DSL is only able to define new terms to be interpreted,
31 no new types, or other type-level structures.
32 .
33 __Warning__
34 .
35 Please be aware that despite its using of powerful ideas from clever people,
36 this remains a FUND-LESS SINGLE-PERSON EXPERIMENTAL LIBRARY.
37 Meaning that it IS NOT heavily tested and documented,
38 DOES NOT have a strong commitment to preserving backward compatibility,
39 MAY FAIL to comply with the <http://www.haskell.org/haskellwiki/Package_versioning_policy PVP>,
40 and CAN die without notice.
41 You've been warned.
42 .
43 __Use cases__
44 .
45 The main goal of this library is to enable the runtime interpretation of terms,
46 type-checked according to some types defined at composing-time (ie. GHC's compile-time).
47 .
48 Using a DSL enables to limit expressiveness in order to ease analysis.
49 Here the idea is that the more complex logic shall remain written in Haskell,
50 and then this library used to project an interface into a DSL
51 (using GHC's Haskell as a FFI (Foreign Function Interface)).
52 This in order to give runtime users the flexibility
53 to write programs not requiring a full-blown Haskell compiler,
54 yet enabling enough flexibility to let them express complex needs
55 with a reasonably advanced type-safe way
56 and a controlled environment of primitives.
57 .
58 Typical use cases:
59 .
60 * Enabling runtime users to enter some Haskell-like expressions
61 (maybe with a more convenient syntax wrt. the domain problem)
62 without using at runtime all the heavy machinery and ecosystem of GHC
63 (eg. by using <https://hackage.haskell.org/package/hint hint>),
64 but still leaning on primitive functions coded in GHC's Haskell.
65 * Limiting those expressions to be built from well-controlled expressions only.
66 * Run some analyzes/optimizations on those well-controlled expressions.
67 .
68 __Usage__
69 .
70 Please pick in <https://hackage.haskell.org/package/symantic-lib symantic-lib>
71 a few specific @Lib/*.hs@ files near what you want to do
72 and the corresponding @Lib\/*/Test.hs@ file,
73 if any in the <git://git.autogeree.net/symantic Git repository>,
74 to learn by examples how to use this library.
75 .
76 Those @Lib\/*/Test.hs@ files use <https://hackage.haskell.org/package/megaparsec megaparsec> as parser
77 (see @Grammar/Megaparsec.hs@) and a default grammar somehow sticking to Haskell's,
78 but staying context-free (so in particular: insensitive to the indentation),
79 and supporting prefix and postfix operators.
80 This grammar — itself written as a symantic embedded DSL
81 with <https://hackage.haskell.org/package/symantic-grammar symantic-grammar> —
82 can be reused to build other ones, is not bound to a specific parser,
83 and can produce its own EBNF rendition.
84 .
85 __Acknowledgements__
86 .
87 This library would probably be much worse than it is
88 without the following seminal works:
89 .
90 * <http://okmij.org/ftp/tagless-final/ Finally Tagless> by Jacques Carette, Oleg Kiselyov, and Chung-chieh Shan.
91 * <http://cs.brynmawr.edu/~rae/papers/2016/thesis/eisenberg-thesis.pdf Dependent Types in Haskell> by Richard A. Eisenberg.
92 .
93 __Main ideas__
94 .
95 * __Symantic DSL__.
96 Terms are encoded in the <http://okmij.org/ftp/tagless-final/ Tagless-Final> way (aka. the /symantic/ way)
97 which leverages the /type class/ system of Haskell — instead of using /data types/ — to form an embedded DSL.
98 More specifically, a /class/ encodes the /syntax/ of terms (eg. 'Sym_Bool')
99 and its /class instances/ on a dedicated type encodes their /semantics/
100 (eg. @(Sym_Bool Eval)@ interprets a term as a value of its type
101 in the host language ('Bool' in Haskell here),
102 or @(Sym_Bool View)@ interprets a term as a textual rendition, etc.).
103
104 DSL are then composed/extended by selecting those symantic /classes/
105 (and in an embedded DSL those could even be automatically inferred,
106 when @NoMonomorphismRestriction@ is on).
107 Otherwise, when using symantics for a non-embedded DSL
108 — the whole point of this library — the /classes/ composing the DSL
109 are selected manually at GHC's compile-time,
110 through the /type-level list/ @ss@ given to 'readTerm'.
111
112 Moreover, those symantic @term@s are parameterized by the type of the value they encode,
113 in order to get the same type safety as with plain Haskell values.
114 Hence the symantic /classes/ have the higher kind: @((* -> *) -> Constraint)@
115 instead of just @(* -> Constraint)@.
116
117 Amongst those symantics, 'Sym_Lambda' introduces /lambda abstractions/ by an higher-order approach,
118 meaning that they directly reuse GHC's internal machinery
119 to abstract or instantiate variables,
120 which I think is by far the most efficient and simplest way of doing it
121 (no (generalized or not) DeBruijn encoding
122 like in <https://hackage.haskell.org/package/bound bound>'s @Monad@s).
123
124 * __Singleton for any type__.
125 To typecheck terms using a @(@'Type'@ src vs t)@ which acts as a /singleton type/
126 for any Haskell /type index/ @t@ of any kind,
127 which is made possible with the dependant Haskell extensions:
128 especially @TypeFamilies@, @GADTs@ and @TypeInType@.
129
130 * __Type constants using 'Typeable'__.
131 /Type constant/ could be introduced by indexing them amongst a /type-level list/,
132 but since they are /monomorphic types/, using 'Typeable' simplifies
133 the machinery, and is likely more space/time efficient, including at GHC-compile-time.
134
135 * __Type variables using a type-level list__.
136 Handling /type variables/ is done by indexing them amongst a @vs@ /type-level list/,
137 where each /type variable/ is wrapped inside a @Proxy@ to handle different kinds.
138 Performing a substitution (in 'substVar') preserves the /type index/ @t@,
139 which is key for preserving any associated 'Term'.
140 Unifying /type variables/ is done with 'unsafeCoerce' (in 'unifyType'),
141 which I think is necessary and likely safe.
142
143 -- NOTE: no longer used.
144 -- * __Extensible data type__.
145 -- To inject a type into a /type-level list/
146 -- or project a /type-level list/ onto a type,
147 -- to compose an /extensible data type/
148 -- (eg. the 'Token' @GADT@ gathering the 'TokenT' /data instances/,
149 -- that a parser can build and then give to 'compile').
150 -- This type-level programming requires @UndecidableInstances@,
151 -- but not @OverlappingInstances@.
152 --
153 -- There is a similarity with
154 -- <http://dx.doi.org/10.1017/S0956796808006758 Data types à la carte>
155 -- (see for instance <https://hackage.haskell.org/package/compdata compdata>
156 -- or <https://hackage.haskell.org/package/syntactic syntactic>).
157 -- Those also enable to compose a DSL using some machinery
158 -- based upon (co)free(r) (co)monads and (cata|ana)morphisms.
159 -- Which library fits best your problem domain and brain is for you to judge :)
160 -- On that topic, see also:
161 -- <https://www.youtube.com/watch?v=qaAKRxO21fU Stop Paying for Free Monads>.
162 --
163 -- Here, I just came up using /type-level lists/ by hacking
164 -- <https://hackage.haskell.org/package/glambda glambda>'s @Elem@.
165 .
166 __Main extensions__
167 .
168 * @ConstraintKinds@ for /type lists/ to contain 'Constraint's,
169 or reifying any 'Constraint' as an explicit dictionary 'Dict',
170 or defining /type synonym/ of /type classes/,
171 or merging /type constraints/.
172 * @DataKinds@ for type-level data structures (eg. /type-level lists/).
173 * @DefaultSignatures@ for providing identity transformations of terms,
174 and thus avoid boilerplate code when a transformation
175 does not need to alter all semantics.
176 Almost as explained in <https://ro-che.info/articles/2016-02-03-finally-tagless-boilerplate Reducing boilerplate in finally tagless style>.
177 * @GADTs@ for knowing types by pattern-matching terms,
178 or building terms by using type classes.
179 * @PolyKinds@ for avoiding a lot of uses of 'Proxy'.
180 * @Rank2Types@ or @ExistentialQuantification@ for parsing @GADT@s.
181 * @TypeApplications@ for having a more concise syntax
182 to build 'Type' (eg. 'tyConst'@ @\@Bool).
183 * @TypeFamilies@ for type-level programming.
184 * @TypeInType@ (introduced in GHC 8.0.1)
185 for 'Type' to also bind a kind equality for the type @t@ it encodes.
186 Which makes the /type application/ ('TyApp')
187 give us an /arrow kind/ for the Haskell /type constructor/
188 it applies an Haskell type to, releaving me from tricky workarounds.
189 * @UndecidableInstances@ for type-level programming that may never terminate.
190 .
191 __Bugs__
192 .
193 There are some of them hidding in there,
194 and the whole thing is far from being perfect…
195 Your comments, problem reports, or questions, are welcome!
196 You have my email address, so… just send me some emails :]
197 .
198 __To do__
199 .
200 * Study to which point /type inferencing/ is doable,
201 now that 'Type' is powerful enough to contain 'TyVar's.
202 * Study to which point error messages can be improved,
203 now that there is a 'Source' carried through all 'Kind's or 'Type's,
204 it should enable some nice reports.
205 Still, a lot of work and testing remain to be done,
206 and likely some ideas to find too…
207 * Add more terms in <https://hackage.haskell.org/package/symantic-lib symantic-lib>.
208 * Add more transformations.
209 * Study how to integrate types into the module system.
210 * Study where to put @INLINE@, @INLINEABLE@ or @SPECIALIZE@ pragmas.
211 * Study how to support /rank-N polymorphic types/,
212 special cases can likely use the /boxed polymorphism/ workaround,
213 but even if GHC were supporting /impredicative types/,
214 I'm currently clueless about how to do this.
215 extra-source-files:
216 extra-tmp-files:
217 -- homepage:
218 license: GPL-3
219 license-file: COPYING
220 maintainer: Julien Moutinho <julm+symantic@autogeree.net>
221 name: symantic
222 stability: experimental
223 synopsis: Library for Typed Tagless-Final Higher-Order Composable DSL
224 tested-with: GHC==8.0.2
225 -- PVP: +-+------- breaking API changes
226 -- | | +----- non-breaking API additions
227 -- | | | +--- code changes with no API change
228 version: 6.0.0.20170618
229
230 Source-Repository head
231 location: git://git.autogeree.net/symantic
232 type: git
233
234 Library
235 default-extensions:
236 DataKinds
237 DefaultSignatures
238 FlexibleContexts
239 FlexibleInstances
240 LambdaCase
241 MultiParamTypeClasses
242 NamedFieldPuns
243 OverloadedStrings
244 Rank2Types
245 ScopedTypeVariables
246 StandaloneDeriving
247 TupleSections
248 TypeApplications
249 TypeFamilies
250 TypeOperators
251 ghc-options: -Wall
252 -fno-warn-tabs
253 default-language: Haskell2010
254 exposed-modules:
255 Language.Symantic
256 Language.Symantic.Compiling
257 Language.Symantic.Compiling.Beta
258 Language.Symantic.Compiling.Grammar
259 Language.Symantic.Compiling.Module
260 Language.Symantic.Compiling.Read
261 Language.Symantic.Compiling.Term
262 Language.Symantic.Interpreting
263 Language.Symantic.Interpreting.Dup
264 Language.Symantic.Interpreting.Eval
265 Language.Symantic.Interpreting.View
266 Language.Symantic.Transforming
267 Language.Symantic.Transforming.Beta
268 Language.Symantic.Transforming.Trans
269 Language.Symantic.Typing
270 Language.Symantic.Typing.Document
271 Language.Symantic.Typing.Grammar
272 Language.Symantic.Typing.Kind
273 Language.Symantic.Typing.List
274 Language.Symantic.Typing.Peano
275 Language.Symantic.Typing.Read
276 Language.Symantic.Typing.Show
277 Language.Symantic.Typing.Type
278 Language.Symantic.Typing.Unify
279 Language.Symantic.Typing.Variable
280 build-depends:
281 base >= 4.6 && < 5
282 , containers
283 , ghc-prim
284 , mono-traversable
285 , symantic-grammar
286 , symantic-document
287 , transformers
288 , text