Copyright | Plow Technologies 2017 |
---|---|
License | BSD3 |
Maintainer | mchaver@gmail.com |
Stability | experimental |
Safe Haskell | None |
Language | Haskell2010 |
OCaml datatype representation of a Haskell datatype. A recursive tree that can be interpreted to output OCaml code. It is meant to encode a Haskell type into OCaml and make json seraliazers that match the output from Generic aeson instances.
- data OCamlDatatype
- data OCamlPrimitive
- = OInt
- | OBool
- | OChar
- | ODate
- | OFloat
- | OString
- | OUnit
- | OList OCamlDatatype
- | OOption OCamlDatatype
- | OEither OCamlDatatype OCamlDatatype
- | OTuple2 OCamlDatatype OCamlDatatype
- | OTuple3 OCamlDatatype OCamlDatatype OCamlDatatype
- | OTuple4 OCamlDatatype OCamlDatatype OCamlDatatype OCamlDatatype
- | OTuple5 OCamlDatatype OCamlDatatype OCamlDatatype OCamlDatatype OCamlDatatype
- | OTuple6 OCamlDatatype OCamlDatatype OCamlDatatype OCamlDatatype OCamlDatatype OCamlDatatype
- data OCamlConstructor
- data ValueConstructor
- data EnumeratorConstructor = EnumeratorConstructor Text
- data OCamlValue
- class OCamlType a where
- data HaskellTypeMetaData = HaskellTypeMetaData Text Text Text
- data OCamlTypeMetaData = OCamlTypeMetaData Text [Text] [Text]
- typeableToOCamlType :: forall a. Typeable a => Proxy a -> OCamlDatatype
- data TypeParameterRef0
- data TypeParameterRef1
- data TypeParameterRef2
- data TypeParameterRef3
- data TypeParameterRef4
- data TypeParameterRef5
- getTypeParameterRefNames :: [OCamlValue] -> [Text]
- getOCamlValues :: ValueConstructor -> [OCamlValue]
- getTypeParameters :: OCamlConstructor -> [Text]
- isTypeParameterRef :: OCamlDatatype -> Bool
- mkModulePrefix :: OCamlTypeMetaData -> OCamlTypeMetaData -> Text
- oCamlValueIsFloat :: OCamlValue -> Bool
Documentation
data OCamlDatatype Source #
Top level of an OCaml datatype. A data type may be composed of primitives and/or a combination of constructors and primitives. OCamlDatatype is recursive via OCamlConstructor -> ValueConstructor -> OCamlValue -> OCamlPrimitive -> OCamlDatatype.
OCamlDatatype HaskellTypeMetaData Text OCamlConstructor | The name of a type and its type constructor |
OCamlPrimitive OCamlPrimitive | A primitive value |
data OCamlPrimitive Source #
Smallest unit of computation in OCaml.
OInt | int |
OBool | bool, boolean |
OChar | char, it gets interpreted as a string because OCaml char does not support UTF-8 |
ODate | Js_date.t |
OFloat | float |
OString | string |
OUnit | () |
OList OCamlDatatype | 'a list, 'a Js_array.t |
OOption OCamlDatatype | 'a option |
OEither OCamlDatatype OCamlDatatype | 'l 'r Aeson.Compatibility.Either.t |
OTuple2 OCamlDatatype OCamlDatatype | (*) |
OTuple3 OCamlDatatype OCamlDatatype OCamlDatatype | (**) |
OTuple4 OCamlDatatype OCamlDatatype OCamlDatatype OCamlDatatype | (***) |
OTuple5 OCamlDatatype OCamlDatatype OCamlDatatype OCamlDatatype OCamlDatatype | (****) |
OTuple6 OCamlDatatype OCamlDatatype OCamlDatatype OCamlDatatype OCamlDatatype OCamlDatatype | (*****) |
data OCamlConstructor Source #
OCamlConstructor take values to create a new instances of a type.
OCamlValueConstructor ValueConstructor | Sum, record (product with named fields) or product without named fields |
OCamlEnumeratorConstructor [EnumeratorConstructor] | Sum of enumerations only. If a sum contains enumerators and at least one constructor with a value then it is an OCamlValueConstructor |
OCamlSumOfRecordConstructor Text ValueConstructor | Sum that contains at least one record. This construction is unique to Haskell. pIt has special Encoding and Decoding rules in order to output a valid OCaml program. i.e. `data A = A {a :: Int} | B {b :: String}` |
data ValueConstructor Source #
OCamlConstructor of one RecordConstructor is a record type. OCamlConstructor of one NamedConstructor that has one value is a Haskell newtype. OCamlConstructor of one NamedConstructor is a product without field names. OCamlConstructor of multiple NamedConstructors is a sum type. OCamlConstructor of at least one RecordConstructor and any other amount of ValueConstructors greater than one is a OCamlSumWithRecordConstructor.
NamedConstructor Text OCamlValue | Product without named fields |
RecordConstructor Text OCamlValue | Product with named fields |
MultipleConstructors [ValueConstructor] | Sum type |
data EnumeratorConstructor Source #
Enumerators have no values, only tags.
EnumeratorConstructor Text | Enumerator and its tag |
data OCamlValue Source #
Expected types of a constructor
OCamlRef HaskellTypeMetaData Text | The name of a non-primitive data type |
OCamlTypeParameterRef Text | Type parameters like |
OCamlEmpty | a place holder for OCaml value. It can represent the end of a list or an Enumerator in a mixed sum |
OCamlPrimitiveRef OCamlPrimitive | A primitive OCaml type like |
OCamlField Text OCamlValue | A field name and its type from a record |
Values OCamlValue OCamlValue | Used for multiple types in a sum type |
class OCamlType a where Source #
Create an OCaml type from a Haskell type. Use the Generic
definition when possible. It also expects ToJSON
and FromJSON
to be derived generically.
toOCamlType :: a -> OCamlDatatype Source #
toOCamlType :: (Generic a, GenericOCamlDatatype (Rep a)) => a -> OCamlDatatype Source #
data HaskellTypeMetaData Source #
Store data about the Haskell origin of a type.
data OCamlTypeMetaData Source #
Store data about the OCaml destination of a type.
typeableToOCamlType :: forall a. Typeable a => Proxy a -> OCamlDatatype Source #
data TypeParameterRef0 Source #
Used to fill the type parameters of proxy types. `Proxy :: Proxy (Maybe TypeParameterRef0)`, `Proxy :: Proxy Either TypeParameterRef0 TypeParameterRef1`. JSON representation is as an Int to simplify the automated tests.
data TypeParameterRef1 Source #
Second unique TypeParameterRef.
data TypeParameterRef2 Source #
Third unique TypeParameterRef.
data TypeParameterRef3 Source #
Fourth unique TypeParameterRef.
data TypeParameterRef4 Source #
Fifth unique TypeParameterRef.
data TypeParameterRef5 Source #
Sixth unique TypeParameterRef.
getTypeParameterRefNames :: [OCamlValue] -> [Text] Source #
Convert OCamlValues to the type parameter names of a data type. `Either a0 a1` -> `["a0","a1"]`
getOCamlValues :: ValueConstructor -> [OCamlValue] Source #
getOCamlValues flatten the values from MultipleConstructors into a list and remove ValueConstructor.
getTypeParameters :: OCamlConstructor -> [Text] Source #
getTypePar
isTypeParameterRef :: OCamlDatatype -> Bool Source #
Matches all of the TypeParameterRefs (TypeParameterRef0 to TypeParameterRef5). This function is needed to work around the tree structure for special rules for rendering type parameters.
mkModulePrefix :: OCamlTypeMetaData -> OCamlTypeMetaData -> Text Source #
Make OCaml module prefix for a value based on the declaration's and parameter's meta data.
oCamlValueIsFloat :: OCamlValue -> Bool Source #
BuckleScript has a float
type that conflicts when you do 'open Aeson.Decode'
float must be appended with Decode
.