-- 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.0
-- | 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
type TypeBridge = TypeInfo -> Maybe TypeInfo
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]
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
data SumType
SumType :: TypeInfo -> [DataConstructor] -> 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
toSumType :: (Generic t, Typeable t, GDataConstructor (Rep t)) => Proxy t -> SumType
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 ()
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
bridgeSumType :: TypeBridge -> SumType -> SumType
-- | Default bridge for mapping primitive/common types: | You can append
-- your own bridges like this: | defaultBridge | myBridge1
-- | myBridge2
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 call writePSTypes like
-- this: | | let myTypes = [ | toSumType (Proxy ::
-- Proxy MyType1) | , toSumType (Proxy ::
-- Proxy MyType2) | ] | writePSTypes defaultBridge
-- "pathtoyoupurescriptproject" myTypes | | You can
-- add new type mappings, like this: | | myBridge =
-- defaultBridge | mySpecialTypeBridge | | Find
-- examples for implementing your own type bridges in: Primitives
-- | A real world use case of this library can be found here. |
-- Last but not least: | WARNING: This function overwrites files - make
-- backups or use version control!
writePSTypes :: TypeBridge -> FilePath -> [SumType] -> IO ()