CSE 130 - Programming Assignment #7 FAQ

  1. 1) I don't understand this error message? "FileNotFoundError: [Errno 2] No such file or directory: './nano/nanoml.byte': './nano/nanoml.byte'"

  2. This means you need to build the "nano/" project. Run 'make' from "nano/".

  3. 1) Do I have to infer polymorphic types? What is the type of e.g. fun x -> x?

  4. Your types should be polymorphic until used. For example, fun x -> x and has the type arrow(V,V), where V is a type variable. You do not need to handle polymorphism in general. For example, you should handle let id = fun x -> x in (id 1) + (id 2), but you don't need to handle let id = fun x -> x in (id 1) < 2 && (id true). These are known as weakly-polymorphic types.

  5. 2a)/2)b Getting "TypeError: unsupported operand type(s) for +: 'NoneType' and 'NoneType'" for fib for any of the decorators.

  6. Did you forget to return a value from the decorated function?

  7. 2b) Getting 'TypeError: unhashable type: ...' in memoizing decorator (

  8. You cannot use lists,dictionaries or any other mutable data type as a key for a python dictionary. You are going to have to figure out a different way to rememer arguments containing dictionaries/lists and the keyword arguments.

  9. 2a) What do I do about exceptions in traced?

  10. You should think carefully what happens to control flow when an exception is thrown? Based on that, think how you need to adjust indentation.

  11. 2b) How do I handle exceptions in memoized?

  12. Exceptions are a value like any other, than can be stored, and then thrown again (read the docs on try/catch/raise).

  13. 2b) Do we have to include keyword args? And also I don't fully understand the question, we just return a value if we call the function twice with the same parameters?

  14. Yes.

  15. Are these two calls the same?
    @memoized 
    def foo(a,b,c): ... 
    
    foo(5,3,2)
    foo(5,c=2,b=3) 

  16. In the first case the decorated function would see 5,3,2 as positional arguments, and in the second it would see 5 as a positional argument, and c=2 and b=3 as keyword arguments. So unfortunately, these would be different calls. (i.e. you can't memoize the second, using the result of the first).

  17. Can I save the output of "run_examples" to a file? (so that I can diff them)

  18. Yes. Create a new python script (lets call it foo.py) with the following contents:

    from decorators import *
    run_examples()
    
    Then from the command line run "python3 foo.py > output.txt" and Voila!