From 5307bab0f0ea3edabe667dfeabacc1184c6ca2f3 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Tue, 19 Sep 2017 22:02:21 +0200 Subject: Reflection --- assignment-2/serialize2start.icl | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'assignment-2') diff --git a/assignment-2/serialize2start.icl b/assignment-2/serialize2start.icl index 61c81d7..d8b5ccc 100644 --- a/assignment-2/serialize2start.icl +++ b/assignment-2/serialize2start.icl @@ -197,6 +197,25 @@ instance == (Bin a) | == a where // better use the generic approach // --- +/** + * Reflection: + * The following is parsed as Just ([], []), which shows that the fact that + * there is no check on the name of the constructor can be exploited. + * + * In the actual Clean implementation, there is the construct `CONS of d` where + * d :: GenericConsDescriptor. This way, the name, arity, etc. of the + * constructor are available as part of the CONS type (even though this type + * does not explicitly contain the information). It is essentially a very + * restricted form of dependent typing, which makes it possible to distinguish + * the _Nil-CONS and the _Cons-CONS at compile-time. + * + * This requires the `CONS of d` construct, so I don't think this exploit is + * fixable in the current setup. It would of course be possible to redefine + * toList and toBin to result in a Maybe and check on the constructor there. + */ +Start :: Maybe ([Int], [String]) +Start = read ["_Cons"] + Start = [ test True , test False -- cgit v1.2.3