{"id":24551957,"url":"https://github.com/mlabs-haskell/plutarch-ctl-bridge","last_synced_at":"2025-10-04T02:30:55.005Z","repository":{"id":168785868,"uuid":"610095058","full_name":"mlabs-haskell/plutarch-ctl-bridge","owner":"mlabs-haskell","description":"CTL bridge done right","archived":false,"fork":false,"pushed_at":"2024-06-14T15:38:54.000Z","size":246,"stargazers_count":4,"open_issues_count":1,"forks_count":0,"subscribers_count":5,"default_branch":"main","last_synced_at":"2024-06-14T16:36:53.146Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Nix","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mlabs-haskell.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-03-06T04:30:27.000Z","updated_at":"2024-06-14T15:32:48.000Z","dependencies_parsed_at":"2024-01-30T19:46:01.542Z","dependency_job_id":"33651b6a-da63-4936-a369-5baba485c742","html_url":"https://github.com/mlabs-haskell/plutarch-ctl-bridge","commit_stats":null,"previous_names":["mlabs-haskell/plutarch-ctl-bridge"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlabs-haskell%2Fplutarch-ctl-bridge","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlabs-haskell%2Fplutarch-ctl-bridge/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlabs-haskell%2Fplutarch-ctl-bridge/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlabs-haskell%2Fplutarch-ctl-bridge/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mlabs-haskell","download_url":"https://codeload.github.com/mlabs-haskell/plutarch-ctl-bridge/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235209703,"owners_count":18953117,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-01-23T01:19:32.204Z","updated_at":"2025-10-04T02:30:54.695Z","avatar_url":"https://github.com/mlabs-haskell.png","language":"Nix","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `plutarch-ctl-bridge`\n\nProject is based on great [purescript-bridge](https://github.com/eskimor/purescript-bridge) library.\n\n## Usage\n\n```haskell\nimport Data.Proxy (Proxy (Proxy))\nimport Language.PureScript.Bridge (defaultBridge, writePSTypes)\nimport Language.PureScript.Bridge.SumType (mkSumType)\n\ntypesToBridge =\n  [ mkSumType (Proxy @MyTypeFoo)\n  , mkSumType (Proxy @MyTypeBar)\n  ]\n\nmain =\n  writePSTypes \"/path/to/save/modules\" (buildBridge defaultBridge) typesToBridge\n```\n\n## Defatult encoding rules\n\nTypes bridged with `mkSumType` are serialized by the following rules.\n\n### Newtypes (`DataEncodingNewtype`/`PlutusTypeNewtype`)\n\nIf type is a newtype, it'll be encoded as internal type\n\n```haskell\nnewtype MyNewtype\n  = MkMyNewtype Bool -- Encoded in the same way `Bool` is encoded\n```\n\n### Enums (`DataEncodingEnum`/`PlutusTypeEnumData`)\n\nIf type is a sum of constructors without fields, it'll be encoded as `I \u003cidx\u003e` where `idx` is an index of a constructor starting from 0\n\n```haskell\ndata MyEnum\n  = MyEnumFoo -- Encoded as `I 0`\n  | MyEnumBar -- Encoded as `I 1`\n```\n\n### Products/Records (`DataEncodingProduct`/`PlutusTypeDataList`)\n\nIf type is a record with only one constructor, it'll be encoded as `List [field0, field1, ..., fieldN]`\n\n```haskell\n-- Encoded as `List [I field1, B field2]`\ndata MyProduct = MyProduct\n  { field1 :: Integer\n  , field2 :: ByteString\n  }\n```\n\n### General sums (`DataEncodingSoP`/`PlutusTypeData`)\n\nOtherwise, type is a general sum of products, it's encoded as `Constr \u003cidx\u003e [fields]` where `idx` is an index of a constructor starting from 0 (like in enums) and `[fields]` is a list of fields (like in records).\n\n```haskell\ndata MySop\n  = MySopFoo Integer Integer -- Encoded as `Constr 0 [I field0, I field1]`\n  | MySopBar ByteString Integer -- Encoded as `Constr 1 [B field0, I field1]`\n```\n\n## Override encoding rules\n\nIf your types are not serialized using above set of rules, use `mkSumTypeWithEncoding` to bridge it to specify encoding flavor. Types bridged with `mkSumTypeWithEncoding` are NOT guaranteed to be correct PureScript code, so make sure you know what you're doing. If you have control over bridge types, make them follow above rules, to guarantee optimal encoding and bridge correctness.\n\n## Known issues\n\nSome PlutusTx types may not be overridden yet to match with CTL equivalents. If you notice some type missing please add it to `Language.PureScript.Bridge.CtlImports` and open a PR.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmlabs-haskell%2Fplutarch-ctl-bridge","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmlabs-haskell%2Fplutarch-ctl-bridge","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmlabs-haskell%2Fplutarch-ctl-bridge/lists"}