{"id":21020948,"url":"https://github.com/awto/poly-dyn","last_synced_at":"2025-09-08T08:34:42.975Z","repository":{"id":5068418,"uuid":"6230308","full_name":"awto/poly-dyn","owner":"awto","description":"Polymorphic dynamics in Haskell","archived":false,"fork":false,"pushed_at":"2012-10-15T18:00:36.000Z","size":120,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-20T13:19:14.915Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Haskell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"puma/puma","license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/awto.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-10-15T16:34:45.000Z","updated_at":"2013-10-29T05:00:00.000Z","dependencies_parsed_at":"2022-09-21T14:10:42.421Z","dependency_job_id":null,"html_url":"https://github.com/awto/poly-dyn","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/awto%2Fpoly-dyn","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/awto%2Fpoly-dyn/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/awto%2Fpoly-dyn/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/awto%2Fpoly-dyn/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/awto","download_url":"https://codeload.github.com/awto/poly-dyn/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243451032,"owners_count":20293055,"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":"2024-11-19T10:44:07.210Z","updated_at":"2025-03-13T17:42:20.557Z","avatar_url":"https://github.com/awto.png","language":"Haskell","funding_links":[],"categories":[],"sub_categories":[],"readme":"Polymorphic dynamics\n====================\n\nThe library provides facilities for packing some subset of polymorphic \nvalues into Dynamic value with erased type information. \n\nThis library, for example, is useful for implementing small un-typed \nscripting languages (external DSL) where it is convenient to export \nsome Haskell's values. Typically this is done by means of some dictionary \nwhich sets name (string) to value correspondence. Haskell's base library \nhas a 'Data.Dynamic.Dynamic' type which is convenient to use for encoding \nsuch values. But it doesn't accept polymorphic values, like \n'show :: Show a =\u003e a -\u003e String'. So some separate value with different \nname should be exported for types we want to support in our DSL. This \nlibrary's Dynamic type can hold values of such type. Though it has \nsignificantly worse performance because it has to unify type's representation \nrather than just compare them like in base library. \n\nUnlike standard dynamics where type's representation is given 'Typeable' \nclass, the library uses explicit type's representation passed as an explicit \nargument to toDynamic and fromDynamic functions. Another option would be using \nIncoherentInstances like in [polytypeable][] but it is dangerous. It is easy \nto miss some instance and get run-time crash, probably even in production \nversion on customer's side. However it is easy to add support of PolyTypeable \ninto the library. The type representation can be generated by TemplateHaskell \nwhich should be implemented in some next version.\n\nThe type constructor of a type pattern('Ty') has 2 phantom parameters, namely \ninput and output type. Generally they are different, since it is possible to \nunpack value to more specific type but it should be forbidden to pack such \nvalues.  For reporting such errors in compile time the library simulates rigid \nvariables where type variables are replaced with predefined ground empty type \nconstructors. So Haskell's type system can unify them only with other type \nvariables.\n\nIt is also possible to pack constrained values, like show function. In this case \nthe value should be wrapped into a type where constraints are replaced with \n\"ProxyC :: Constraint -\u003e *\" parameters. And obviously the dictionary lookup \nshould be performed manually in runtime. E.g. with may be a Map if the constraint \ntype is ground or it may use logic programming libraries such as [logict][] along \nwith [unification-fd][] for more advanced search for an instance. Some next version \nof the library may provide facilities for this. \n\nTODO\n----\n\n* TemplateHaskell generators for type patterns\n* Facilities for dictionary search\n* Factor out ground type representation for better performance\n* PolyTypeable type representation option\n\n[polytypeable]: http://hackage.haskell.org/package/polytypeable\n[logict]: http://hackage.haskell.org/package/logict \n[unification-fd]: http://hackage.haskell.org/package/unification-fd\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fawto%2Fpoly-dyn","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fawto%2Fpoly-dyn","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fawto%2Fpoly-dyn/lists"}