on master help sign in
update documentation to remove Atomable references and discuss new ADT implementation
commitb5a81b3d60b5814f2da6b3a05fdd2efd84144740 authorAgentM <agentm@themactionfaction.com> dateMon 6 Feb 2017, 00:27 (10 years ago) parentbababa6
1 file changed+25−7
docs/new_datatypes.markdown+25−7
docs/new_datatypes.markdown+25−7
@@ -39,13 +39,31 @@ Note that the Haskell-standard "Maybe a" and "Either a b" data types are include
3939
4040## Support for Haskell Types
4141
42−Any Haskell data type which is an instance of ```Atomable``` is a candidate for a Project:M36 value called an ```Atom```. Database tuples are composed of Atoms.
43−
44−Project:M36 does not yet support dynamically-loaded components, so the data type must be compiled into the Project:M36 backend.
42+New algebraic data types can be added to the database context at any time via TutorialD or Haskell. Typeclasses for database types are not supported.
4543
4644### Implementation for Haskell Types
4745
48−1. Create an instance of your data type for the ```Atomable``` typeclass. The ```Atomable``` typeclass implies instances for a variety of standard typeclasses.
49−1. Update the ```Binary Atom``` instance to include deserialization for your type.
50−1. Update the ```makeAtomFromText``` in ```ProjectM36/Atom.hs``` to support CSV import.
51−1. Optionally adjust ```TutorialD/Interpreter/RelationalExpression.hs``` to add support for parsing your data type in the TutorialD interpreter. Look for ```atomP```.
46+Given a ```ProjectM36.Client``` ```Connection```, create an ```AddTypeConstructor``` with arguments a) type constructor name and b) data constructors.
47+
48+Example:
49+```haskell
50+AddTypeConstructor (ADTypeConstructorDef "Hair" []) [DataConstructorDef "Brown" [], DataConstructorDef "Blond" [], DataConstructorDef "Bald" [],...]
51+```
52+
53+Pass the ```AddTypeConstructor``` value to ```executeDatabaseContextExpr``` to add it to the database.
54+
55+To create a value for the new algebraic data type, create the type:
56+
57+```haskell
58+let hairType = ConstructedAtomType "Hair" M.empty
59+```
60+
61+then create the value:
62+
63+```haskell
64+let blondAtom = ConstructedAtom "Blond" hairType []
65+```
66+
67+The ```blondAtom``` can now be used in any place where an Atom is otherwise used such as in ```AtomExpr``` checking for equality in restriction or as an argument to ```AtomFunction```s or simply in building a new relation.
68+
69+In the previous example, the additional empty arguments are for polymorphic variables and arguments. In this simple ADT, there is no polymorphism necessary, so the arguments are empty.