diff options
author | Camil Staps | 2017-09-19 22:02:21 +0200 |
---|---|---|
committer | Camil Staps | 2017-09-19 22:02:21 +0200 |
commit | 5307bab0f0ea3edabe667dfeabacc1184c6ca2f3 (patch) | |
tree | e500051559b0ae39ec95d4fee50f546eee20cc10 /assignment-2 | |
parent | Pretty-printing (diff) |
Reflection
Diffstat (limited to 'assignment-2')
-rw-r--r-- | assignment-2/serialize2start.icl | 19 |
1 files changed, 19 insertions, 0 deletions
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
|