5 ms·
Most undergraduates take a compiler course in which they implement C, Java or Scheme. I have yet to see a course at any university, however, in which Haskel
by siraben 7y ago
Most undergraduates take a compiler course in which they implement
C, Java or Scheme. I have yet to see a course at any university,
however, in which Haskell is used as the project language. [...] The
closest project I’ve seen to this is a minimal Haskell dialect
called duet.
Ben Lynn has been working on such a Haskell compiler[0], self-hosting and with IO too. It's a little unusual in its approach to compilation (targets combinatory logic and executes via graph reduction), but it's a great example nonetheless, from which one could build an undergraduate course.
Code generation is a difficult issue, compiling a lazy functional language to assembly could easily fill up two semesters of classes alone.
The VM in C is really small and the compiler can be built up incrementally[1].
[0] https://github.com/blynn/compiler https://github.com/blynn/compiler
[1] https://crypto.stanford.edu/~blynn/compiler/quest.html https://crypto.stanford.edu/~blynn/compiler/quest.html
- arianvanp 7y agoWe have https://hackage.haskell.org/package/helium https://hackage.haskell.org/package/helium at our university which is being used for teaching. It's pretty close to Haskell 98 compliant
- tluyben2 7y agoI used this or similar (I forgot the name back then) when I was at UU decades ago; it was quite pleasant to work with as a teaching tool compared to ghc, esp at that time.
- vanusa 7y agoI have yet to see a course at any university, however, in which Haskell is used as the project language. Given the language's inherent complexity (and tortured history) -- is the task of writing a Haskell compiler really suitable for the undergraduate curriculum? That is, for "mere mortals". Not the kind who take tons and tons of graduate courses. In which case we'd be speaking of graduate-level courses.
- przemo_li 7y agoAssess for yourself: https://en.m.wikibooks.org/wiki/Write_Yourself_a_Scheme_in_48_Hours https://en.m.wikibooks.org/wiki/Write_Yourself_a_Scheme_in_4... For me, it's easy enough to follow.
- omaranto 7y ago> Most undergraduates take a compiler course in which they implement C, Java or Scheme. Is that true? I thought those compiler courses typically implemented some toy language. Maybe "in" is misplaced and the following was meant instead? "Most undergraduates take a compiler course which they implement in C, Java or Scheme."
- leetcrew 7y agoI think you're essentially right, but the "toy language" is often a subset of some real language. in my compilers course it was a subset of pascal, which targeted a very friendly IR. there's no inherent reason why the same couldn't be done for a subset of C, Java, or Scheme. in particular, Scheme has a relatively simple syntax to parse. C is fairly difficult to parse, not sure to what degree the grammar can be simplified by removing features.