From 90d06d036ded489a21f61a997943c5254fdf14cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=BE=E9=9B=A8=E9=AD=94=E7=90=86=E6=B2=99?= Date: Wed, 27 Mar 2019 15:52:56 -0700 Subject: [PATCH] [Relay] clean up hd, change tl the comment for hd is wrong - type checking fail because it should (there is no sensible match) and I strongly argue against having a nil_case for tl that return silently: 0: it is bad to silent error and return a 'very innocent value'. suppose tl actually got passed a nil somewhere in code. it will return a nil, and it will continue execution as if everything is normal (because nil is completely normal in list (it does not mean null)). it might trigger more silent error, returning more and more 'nil', and in the end you get the wrong value. Now this is extremely hard to debug, as you can not know which nil is 'nil because of failed tl match' or 'nil because it denote a completely normal empty list'. 1: it is not how tl/cdr is defined in scheme/ocaml/haskell/etc. it will confuse people. --- python/tvm/relay/prelude.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/python/tvm/relay/prelude.py b/python/tvm/relay/prelude.py index fb8c58bf431e..6cf104ab388a 100644 --- a/python/tvm/relay/prelude.py +++ b/python/tvm/relay/prelude.py @@ -29,7 +29,6 @@ def define_list_hd(self): x = Var("x", self.l(a)) y = Var("y") z = Var("z") - # Don't match nil() since it will break type checking cons_case = Clause(PatternConstructor(self.cons, [PatternVar(y), PatternVar(z)]), y) self.mod[self.hd] = Function([x], Match(x, [cons_case]), a, [a]) @@ -43,9 +42,8 @@ def define_list_tl(self): x = Var("x", self.l(a)) y = Var("y") z = Var("z") - nil_case = Clause(PatternConstructor(self.nil, []), self.nil()) cons_case = Clause(PatternConstructor(self.cons, [PatternVar(y), PatternVar(z)]), z) - self.mod[self.tl] = Function([x], Match(x, [nil_case, cons_case]), self.l(a), [a]) + self.mod[self.tl] = Function([x], Match(x, [cons_case]), self.l(a), [a]) def define_list_nth(self): """Defines a function to get the nth element of a list.