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.
Synopsis
- data OCamlDatatype
- data OCamlPrimitive
- = OBool
- | OChar
- | ODate
- | OFloat
- | OInt
- | OInt32
- | 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
- toOCamlType :: a -> OCamlDatatype
- data HaskellTypeMetaData = HaskellTypeMetaData Text Text Text
- data OCamlTypeMetaData = OCamlTypeMetaData Text [Text] [Text]
- typeableToOCamlType :: forall a. Typeable a => Proxy a -> OCamlDatatype
- newtype TypeParameterRef0 = TypeParameterRef0 Int
- newtype TypeParameterRef1 = TypeParameterRef1 Int
- data TypeParameterRef2 = TypeParameterRef2 Int
- data TypeParameterRef3 = TypeParameterRef3 Int
- data TypeParameterRef4 = TypeParameterRef4 Int
- data TypeParameterRef5 = TypeParameterRef5 Int
- getTypeParameterRefNames :: [OCamlValue] -> [Text]
- getOCamlValues :: ValueConstructor -> [OCamlValue]
- getTypeParameters :: OCamlConstructor -> [Text]
- isTypeParameterRef :: OCamlDatatype -> Bool
- mkModulePrefix :: OCamlTypeMetaData -> OCamlTypeMetaData -> Text
- oCamlValueIsFloat :: OCamlValue -> Bool
- typeRepToHaskellTypeMetaData :: TypeRep -> HaskellTypeMetaData
- tyConToHaskellTypeMetaData :: TyCon -> HaskellTypeMetaData
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 |
Instances
Eq OCamlDatatype Source # | |
Defined in OCaml.BuckleScript.Types (==) :: OCamlDatatype -> OCamlDatatype -> Bool # (/=) :: OCamlDatatype -> OCamlDatatype -> Bool # | |
Show OCamlDatatype Source # | |
Defined in OCaml.BuckleScript.Types showsPrec :: Int -> OCamlDatatype -> ShowS # show :: OCamlDatatype -> String # showList :: [OCamlDatatype] -> ShowS # |
data OCamlPrimitive Source #
Smallest unit of computation in OCaml.
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 |
OInt | int |
OInt32 | int32 |
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 | (*****) |
Instances
Eq OCamlPrimitive Source # | |
Defined in OCaml.BuckleScript.Types (==) :: OCamlPrimitive -> OCamlPrimitive -> Bool # (/=) :: OCamlPrimitive -> OCamlPrimitive -> Bool # | |
Show OCamlPrimitive Source # | |
Defined in OCaml.BuckleScript.Types showsPrec :: Int -> OCamlPrimitive -> ShowS # show :: OCamlPrimitive -> String # showList :: [OCamlPrimitive] -> ShowS # |
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. It has special Encoding and Decoding rules in order to output a valid OCaml program. i.e. `data A = A {a :: Int} | B {b :: String}` |
Instances
Eq OCamlConstructor Source # | |
Defined in OCaml.BuckleScript.Types (==) :: OCamlConstructor -> OCamlConstructor -> Bool # (/=) :: OCamlConstructor -> OCamlConstructor -> Bool # | |
Show OCamlConstructor Source # | |
Defined in OCaml.BuckleScript.Types showsPrec :: Int -> OCamlConstructor -> ShowS # show :: OCamlConstructor -> String # showList :: [OCamlConstructor] -> ShowS # |
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 |
Instances
Eq ValueConstructor Source # | |
Defined in OCaml.BuckleScript.Types (==) :: ValueConstructor -> ValueConstructor -> Bool # (/=) :: ValueConstructor -> ValueConstructor -> Bool # | |
Show ValueConstructor Source # | |
Defined in OCaml.BuckleScript.Types showsPrec :: Int -> ValueConstructor -> ShowS # show :: ValueConstructor -> String # showList :: [ValueConstructor] -> ShowS # |
data EnumeratorConstructor Source #
Enumerators have no values, only tags.
EnumeratorConstructor Text | Enumerator and its tag |
Instances
Eq EnumeratorConstructor Source # | |
Defined in OCaml.BuckleScript.Types (==) :: EnumeratorConstructor -> EnumeratorConstructor -> Bool # (/=) :: EnumeratorConstructor -> EnumeratorConstructor -> Bool # | |
Show EnumeratorConstructor Source # | |
Defined in OCaml.BuckleScript.Types showsPrec :: Int -> EnumeratorConstructor -> ShowS # show :: EnumeratorConstructor -> String # showList :: [EnumeratorConstructor] -> ShowS # |
data OCamlValue Source #
Expected types of a constructor
OCamlRef HaskellTypeMetaData Text | The name of a non-primitive data type |
OCamlRefApp TypeRep OCamlValue | A type constructor that has at least one type parameter filled |
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 NameConstructor or a RecordConstructor. |
OCamlRefAppValues OCamlValue OCamlValue | User for multiple types in an OCamlRefApp. These are rendered in a different way from Values. |
Instances
Eq OCamlValue Source # | |
Defined in OCaml.BuckleScript.Types (==) :: OCamlValue -> OCamlValue -> Bool # (/=) :: OCamlValue -> OCamlValue -> Bool # | |
Show OCamlValue Source # | |
Defined in OCaml.BuckleScript.Types showsPrec :: Int -> OCamlValue -> ShowS # show :: OCamlValue -> String # showList :: [OCamlValue] -> ShowS # |
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.
Nothing
toOCamlType :: a -> OCamlDatatype Source #
toOCamlType :: (Generic a, GenericOCamlDatatype (Rep a)) => a -> OCamlDatatype Source #
Instances
data HaskellTypeMetaData Source #
Store data about the Haskell origin of a type.
Instances
Eq HaskellTypeMetaData Source # | |
Defined in OCaml.BuckleScript.Types (==) :: HaskellTypeMetaData -> HaskellTypeMetaData -> Bool # (/=) :: HaskellTypeMetaData -> HaskellTypeMetaData -> Bool # | |
Ord HaskellTypeMetaData Source # | |
Defined in OCaml.BuckleScript.Types compare :: HaskellTypeMetaData -> HaskellTypeMetaData -> Ordering # (<) :: HaskellTypeMetaData -> HaskellTypeMetaData -> Bool # (<=) :: HaskellTypeMetaData -> HaskellTypeMetaData -> Bool # (>) :: HaskellTypeMetaData -> HaskellTypeMetaData -> Bool # (>=) :: HaskellTypeMetaData -> HaskellTypeMetaData -> Bool # max :: HaskellTypeMetaData -> HaskellTypeMetaData -> HaskellTypeMetaData # min :: HaskellTypeMetaData -> HaskellTypeMetaData -> HaskellTypeMetaData # | |
Show HaskellTypeMetaData Source # | |
Defined in OCaml.BuckleScript.Types showsPrec :: Int -> HaskellTypeMetaData -> ShowS # show :: HaskellTypeMetaData -> String # showList :: [HaskellTypeMetaData] -> ShowS # |
data OCamlTypeMetaData Source #
Store data about the OCaml destination of a type.
Instances
Eq OCamlTypeMetaData Source # | |
Defined in OCaml.BuckleScript.Types (==) :: OCamlTypeMetaData -> OCamlTypeMetaData -> Bool # (/=) :: OCamlTypeMetaData -> OCamlTypeMetaData -> Bool # | |
Ord OCamlTypeMetaData Source # | |
Defined in OCaml.BuckleScript.Types compare :: OCamlTypeMetaData -> OCamlTypeMetaData -> Ordering # (<) :: OCamlTypeMetaData -> OCamlTypeMetaData -> Bool # (<=) :: OCamlTypeMetaData -> OCamlTypeMetaData -> Bool # (>) :: OCamlTypeMetaData -> OCamlTypeMetaData -> Bool # (>=) :: OCamlTypeMetaData -> OCamlTypeMetaData -> Bool # max :: OCamlTypeMetaData -> OCamlTypeMetaData -> OCamlTypeMetaData # min :: OCamlTypeMetaData -> OCamlTypeMetaData -> OCamlTypeMetaData # | |
Show OCamlTypeMetaData Source # | |
Defined in OCaml.BuckleScript.Types showsPrec :: Int -> OCamlTypeMetaData -> ShowS # show :: OCamlTypeMetaData -> String # showList :: [OCamlTypeMetaData] -> ShowS # |
typeableToOCamlType :: forall a. Typeable a => Proxy a -> OCamlDatatype Source #
for any type that does not use the same serialization as Generic Aeson and has a manually written OCaml definition, should manually derive OCamlType using this function for convenience.
instance OCamlType X where toOCamlType _ = typeableToOCamlType (Proxy :: Proxy X)
newtype 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.
Instances
newtype TypeParameterRef1 Source #
Second unique TypeParameterRef.
Instances
data TypeParameterRef2 Source #
Third unique TypeParameterRef.
Instances
data TypeParameterRef3 Source #
Fourth unique TypeParameterRef.
Instances
data TypeParameterRef4 Source #
Fifth unique TypeParameterRef.
Instances
data TypeParameterRef5 Source #
Sixth unique TypeParameterRef.
Instances
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 #
get all of the type parameters from an OCamlConstructor.
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
.
typeRepToHaskellTypeMetaData :: TypeRep -> HaskellTypeMetaData Source #
convert TypeRep to HaskellTypeMetaData
tyConToHaskellTypeMetaData :: TyCon -> HaskellTypeMetaData Source #
convert TyCon to HaskellTypeMetaData