From 964ec62d4fbcc1fb2336a3de355ce3554ef7eb04 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Wed, 8 Sep 2021 00:22:45 -0400 Subject: Now using eval to derive code for arbitrary types. --- stdlib/source/library/lux/type/poly.lux | 28 +++------------------------- 1 file changed, 3 insertions(+), 25 deletions(-) (limited to 'stdlib/source/library') diff --git a/stdlib/source/library/lux/type/poly.lux b/stdlib/source/library/lux/type/poly.lux index 5bc9254c8..4f7a32f1c 100644 --- a/stdlib/source/library/lux/type/poly.lux +++ b/stdlib/source/library/lux/type/poly.lux @@ -34,42 +34,20 @@ (syntax: .public (poly: [[export_policy name body] ..polyP]) (with_identifiers [g!_ g!type g!output] (let [g!name (code.identifier ["" name])] - (in (.list (` ((~! syntax:) (~ export_policy) ((~ g!name) [(~ g!type) (~! .identifier)]) + (in (.list (` ((~! syntax:) (~ export_policy) ((~ g!name) [(~ g!type) (~! .any)]) ((~! do) (~! meta.monad) - [(~ g!type) ((~! meta.type_definition) (~ g!type))] + [(~ g!type) ((~! meta.eval) .Type (~ g!type))] (case (: (.Either .Text .Code) ((~! .result) ((~! <>.rec) (function ((~ g!_) (~ g!name)) (~ body))) - (~ g!type))) + (.:as .Type (~ g!type)))) (#.Left (~ g!output)) ((~! meta.failure) (~ g!output)) (#.Right (~ g!output)) ((~' in) (.list (~ g!output)))))))))))) -(def: derivedP - (Parser [Code Text [Name (List Name)] (Maybe Code)]) - (let [private ($_ <>.and - .local_identifier - (.form (<>.and .identifier (<>.many .identifier))) - (<>.maybe .any))] - (<>.either (<>.and .any private) - (<>.and (<>\in (` .private)) private)))) - -(syntax: .public (derived: [[export_policy name [poly_func poly_args] ?custom_impl] ..derivedP]) - (do [! meta.monad] - [poly_args (monad.each ! meta.normal poly_args) - .let [impl (case ?custom_impl - (#.Some custom_impl) - custom_impl - - #.None - (` ((~ (code.identifier poly_func)) (~+ (list\each code.identifier poly_args)))))]] - (in (.list (` (def: (~ export_policy) (~ (code.identifier ["" name])) - {#.implementation? #1} - (~ impl))))))) - (def: .public (code env type) (-> Env Type Code) (`` (case type -- cgit v1.2.3