-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Generate PureScript data types from Haskell data types -- -- Generate PureScript data types from Haskell data types @package purescript-bridge @version 0.3.0.4 -- | As we translate types and not type constructors, we have to pass dummy -- types to any type constructor. doBridge will translate all parameter -- types which come from a module TypeParameters (e.g. this one) to lower -- case. E.g. for translating something like Maybe: data Maybe' a = -- Nothing' | Just' a you would use: import Bridge -- import TypeParameters toSumType (Proxy :: Proxy (Maybe A)) -- -- Note the capital A, which comes from the TypeParameters module. module Language.PureScript.Bridge.TypeParameters data A data B data C data D data E data F data G data H data I data J data K data L data M data N data O data P data Q data R data S data T data U data V data W data X data Y data Z -- | You can use those if your type parameters are actually type -- constructors as well: toSumType (Proxy :: Proxy (ReaderT -- R M1 A)) data A1 a data B1 a data C1 a data D1 a data E1 a data F1 a data G1 a data H1 a data I1 a data J1 a data K1 a data L1 a data M1 a data N1 a data O1 a data P1 a data Q1 a data R1 a data S1 a data T1 a data U1 a data V1 a data W1 a data X1 a data Y1 a data Z1 a module Language.PureScript.Bridge.TypeInfo -- | Translates a Haskell type info to a PureScript type info: type TypeBridge = TypeInfo -> Maybe TypeInfo -- | Basic info about a data type: data TypeInfo TypeInfo :: !Text -> !Text -> !Text -> ![TypeInfo] -> TypeInfo -- | Hackage package [typePackage] :: TypeInfo -> !Text -- | Full Module path [typeModule] :: TypeInfo -> !Text [typeName] :: TypeInfo -> !Text [typeParameters] :: TypeInfo -> ![TypeInfo] mkTypeInfo :: Typeable t => Proxy t -> TypeInfo mkTypeInfo' :: TypeRep -> TypeInfo -- | Put the TypeInfo in a list together with all its typeParameters -- (recursively) flattenTypeInfo :: TypeInfo -> [TypeInfo] -- | Little helper for type bridge implementers eqTypeName :: Text -> TypeInfo -> Bool instance GHC.Show.Show Language.PureScript.Bridge.TypeInfo.TypeInfo instance GHC.Classes.Eq Language.PureScript.Bridge.TypeInfo.TypeInfo module Language.PureScript.Bridge.Tuple data TupleParserState Start :: TupleParserState OpenFound :: TupleParserState ColonFound :: TupleParserState Tuple :: TupleParserState NoTuple :: TupleParserState tupleBridge :: TypeBridge step :: TupleParserState -> Char -> TupleParserState isTuple :: Text -> Bool instance GHC.Show.Show Language.PureScript.Bridge.Tuple.TupleParserState instance GHC.Classes.Eq Language.PureScript.Bridge.Tuple.TupleParserState module Language.PureScript.Bridge.Primitives boolBridge :: TypeBridge intBridge :: TypeBridge stringBridge :: TypeBridge listBridge :: TypeBridge maybeBridge :: TypeBridge eitherBridge :: TypeBridge module Language.PureScript.Bridge.SumType -- | Generic representation of your Haskell types, the contained (leaf) -- types can be modified to match compatible PureScript types, by using -- TypeBridge functions like defaultBridge with -- writePSTypes. data SumType SumType :: TypeInfo -> [DataConstructor] -> SumType -- | Create a representation of your sum (and product) types, for doing -- type translations and writing it out to your PureScript modules. In -- order to get the type information we use a dummy variable of type -- Proxy (YourType). toSumType :: (Generic t, Typeable t, GDataConstructor (Rep t)) => Proxy t -> SumType data DataConstructor DataConstructor :: !Text -> !(Either [TypeInfo] [RecordEntry]) -> DataConstructor [sigConstructor] :: DataConstructor -> !Text [sigValues] :: DataConstructor -> !(Either [TypeInfo] [RecordEntry]) data RecordEntry RecordEntry :: !Text -> !TypeInfo -> RecordEntry [recLabel] :: RecordEntry -> !Text [recValue] :: RecordEntry -> !TypeInfo class GDataConstructor f gToConstructors :: GDataConstructor f => f a -> [DataConstructor] class GRecordEntry f gToRecordEntries :: GRecordEntry f => f a -> [RecordEntry] getUsedTypes :: SumType -> [TypeInfo] constructorToType :: DataConstructor -> [TypeInfo] -> [TypeInfo] instance GHC.Show.Show Language.PureScript.Bridge.SumType.SumType instance GHC.Show.Show Language.PureScript.Bridge.SumType.DataConstructor instance GHC.Show.Show Language.PureScript.Bridge.SumType.RecordEntry instance (GHC.Generics.Datatype a, Language.PureScript.Bridge.SumType.GDataConstructor c) => Language.PureScript.Bridge.SumType.GDataConstructor (GHC.Generics.D1 a c) instance (Language.PureScript.Bridge.SumType.GDataConstructor a, Language.PureScript.Bridge.SumType.GDataConstructor b) => Language.PureScript.Bridge.SumType.GDataConstructor (a GHC.Generics.:+: b) instance (GHC.Generics.Constructor a, Language.PureScript.Bridge.SumType.GRecordEntry b) => Language.PureScript.Bridge.SumType.GDataConstructor (GHC.Generics.C1 a b) instance (Language.PureScript.Bridge.SumType.GRecordEntry a, Language.PureScript.Bridge.SumType.GRecordEntry b) => Language.PureScript.Bridge.SumType.GRecordEntry (a GHC.Generics.:*: b) instance Language.PureScript.Bridge.SumType.GRecordEntry GHC.Generics.U1 instance (GHC.Generics.Selector a, Data.Typeable.Internal.Typeable t) => Language.PureScript.Bridge.SumType.GRecordEntry (GHC.Generics.S1 a (GHC.Generics.K1 GHC.Generics.R t)) module Language.PureScript.Bridge.Printer data PSModule PSModule :: !Text -> !(Map Text ImportLine) -> ![SumType] -> PSModule [psModuleName] :: PSModule -> !Text [psImportLines] :: PSModule -> !(Map Text ImportLine) [psTypes] :: PSModule -> ![SumType] data ImportLine ImportLine :: !Text -> !(Set Text) -> ImportLine [importModule] :: ImportLine -> !Text [importTypes] :: ImportLine -> !(Set Text) type Modules = Map Text PSModule type ImportLines = Map Text ImportLine printModule :: FilePath -> PSModule -> IO () sumTypesToNeededPackages :: [SumType] -> Set Text sumTypeToNeededPackages :: SumType -> Set Text moduleToText :: PSModule -> Text importLineToText :: ImportLine -> Text sumTypeToText :: SumType -> Text constructorToText :: Int -> DataConstructor -> Text recordEntryToText :: RecordEntry -> Text typeInfoToText :: TypeInfo -> Text sumTypesToModules :: Modules -> [SumType] -> Modules sumTypeToModule :: SumType -> Modules -> Modules typesToImportLines :: ImportLines -> [TypeInfo] -> ImportLines typeToImportLines :: TypeInfo -> ImportLines -> ImportLines unlessM :: Monad m => m Bool -> m () -> m () instance GHC.Show.Show Language.PureScript.Bridge.Printer.PSModule instance GHC.Show.Show Language.PureScript.Bridge.Printer.ImportLine module Language.PureScript.Bridge -- | Translate leaf types in a sum type to match PureScript types. bridgeSumType :: TypeBridge -> SumType -> SumType -- | Default bridge for mapping primitive/common types: You can append your -- own bridges like this: -- --
-- defaultBridge <|> myBridge1 <|> myBridge2 ---- -- Find examples for bridge definitions in -- Language.PureScript.Bridge.Primitives and -- Language.PureScript.Bridge.Tuple. defaultBridge :: TypeBridge -- | Your entry point to this library and quite likely all you will need. -- Make sure all your types derive Generic and Typeable. Typeable is not -- needed from ghc-7.10 on. -- -- Then list all your types you want to use in PureScript and call -- writePSTypes: -- --
-- let myTypes = [ -- toSumType (Proxy :: Proxy MyType1) -- , toSumType (Proxy :: Proxy MyType2) -- ] -- -- writePSTypes defaultBridge "path/to/your/purescript/project" myTypes ---- -- You can define your own type bridges based on defaultBridge: -- --
-- myBridge = 'defaultBridge' <|> mySpecialTypeBridge ---- -- and use it with writePSTypes: -- --
-- writePSTypes myBridge "path/to/your/purescript/project" myTypes ---- -- Find examples for implementing your own type bridges in: -- Language.PureScript.Bridge.Primitives. -- --