This PR adds a tiny standard library for the example language. This allows shortening slightly the current tests. More importantly, it will help maximise sharing of usual functions in other tests, and I am planning to write quite a few of those in the future.
Technically, the example language does not support any notion of imports. Since the code of the tests would use those standard functions without defining them itself, the type checker would reject those pieces of code because they use undefined functions. One solution is to use the quasi-quoter progNoTC (read “program with no type-checking”), then to merge the resulting unchecked definitions with the ones from the standard library, and then only to call the type-checker. I attempted to make this slightly easier by providing a quasi-quoter progWithStdLib which basically does this under the hood. I don't know if that's the best design so I'm very open to remarks/suggestions.
Things that aren't that great yet:
There is no notion of namespacing or modules, so all the names of the standard library are in the scope and that's it. This might become annoying if we want similar function names acting on different structures. Maybe we should consider prefixing all the functions in the standard library by the structure they act on. eg. Maybe_map vs. List_map, etc. (I'm not particularly attached to the underscore.)
~I don't currently type-check the standard library, meaning that the errors in it will only be found by and attributed to the quasi-quoter progWithStdLib when used somewhere else. This shouldn't be too hard to fix: one probably just want to run the type checker when creating the stdLib value.~ Edit: fixed in 1a06ec3300f7e5ca8cec025b4988e5eb7f2eeb90. Somehow, the output from Template Haskell is prettier and doesn't include the unreadable Code: part. But this is good enough IMHO.
~I don't provide a function other than unionPrtUODefs while only allows to combine definitions two by two, meaning we will have to call it a number of times linear in the number of “modules” (maybe a better word is “parts”) in the standard library. This is also pretty easy to fix.~ Edit: fixed in f6ffe07.
This PR adds a tiny standard library for the example language. This allows shortening slightly the current tests. More importantly, it will help maximise sharing of usual functions in other tests, and I am planning to write quite a few of those in the future.
Technically, the example language does not support any notion of imports. Since the code of the tests would use those standard functions without defining them itself, the type checker would reject those pieces of code because they use undefined functions. One solution is to use the quasi-quoter
progNoTC
(read “program with no type-checking”), then to merge the resulting unchecked definitions with the ones from the standard library, and then only to call the type-checker. I attempted to make this slightly easier by providing a quasi-quoterprogWithStdLib
which basically does this under the hood. I don't know if that's the best design so I'm very open to remarks/suggestions.Things that aren't that great yet:
There is no notion of namespacing or modules, so all the names of the standard library are in the scope and that's it. This might become annoying if we want similar function names acting on different structures. Maybe we should consider prefixing all the functions in the standard library by the structure they act on. eg.
Maybe_map
vs.List_map
, etc. (I'm not particularly attached to the underscore.)~I don't currently type-check the standard library, meaning that the errors in it will only be found by and attributed to the quasi-quoter
progWithStdLib
when used somewhere else. This shouldn't be too hard to fix: one probably just want to run the type checker when creating thestdLib
value.~ Edit: fixed in 1a06ec3300f7e5ca8cec025b4988e5eb7f2eeb90. Somehow, the output from Template Haskell is prettier and doesn't include the unreadableCode:
part. But this is good enough IMHO.~I don't provide a function other than
unionPrtUODefs
while only allows to combine definitions two by two, meaning we will have to call it a number of times linear in the number of “modules” (maybe a better word is “parts”) in the standard library. This is also pretty easy to fix.~ Edit: fixed in f6ffe07.What do you guys think?