Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
- bridgeSumType :: TypeBridge -> SumType -> SumType
- defaultBridge :: TypeBridge
- writePSTypes :: TypeBridge -> FilePath -> [SumType] -> IO ()
Documentation
bridgeSumType :: TypeBridge -> SumType -> SumType Source
Translate leaf types in a sum type to match PureScript types.
defaultBridge :: TypeBridge Source
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.
writePSTypes :: TypeBridge -> FilePath -> [SumType] -> IO () Source
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.
Result:
writePSTypes
will write out PureScript modules to the given path, mirroring the hierarchy of the Haskell modules
the types came from. In addition a list of needed PS packages is printed to the console.
The list of needed packages is retrieved from the bridged TypeInfo
data, so make sure you set typePackage
correctly
in your own bridges, in order for this feature to be useful.
Real world usage example:
A real world use case of this library can be found here.
WARNING:
This function overwrites files - make backups or use version control!