7 ms·
Write Yourself a Scheme in 48 Hours
- cosarara97 12y ago> Wikibooks does not have a page with this exact name. ?
- cosarara97 12y agoOh, http://en.wikibooks.org/wiki/Write_Yourself_a_Scheme_in_48_Hours http://en.wikibooks.org/wiki/Write_Yourself_a_Scheme_in_48_H... (without slash at the end)
- sctb 12y agoThanks, we updated the link.
- arianvanp 12y agoThis was my very first 'big' haskell project! I had a lot of fun making it and afterwards I decided to start following compilers courses at my university!(https://github.com/arianvp/Haskeme https://github.com/arianvp/Haskeme). I'd recommend anyone dabbling in their first days of haskell to take a try at this project. You will learn a great deal and most of all it's just extremely cool. Was a lot of fun to build and I would do it totally differently if I would do it again. For example I would've added lexical scoping and handle variables with a Reader or State instead of IORefs . It's quite possible to make an almost fully pure implementation without using I/O for variables.
- tpush 12y agoHow would you implement mutable closures without using IORefs, though? In Scheme the environment that is captured by a lambda expression is mutable; how would you accomplish that without IORefs? (Genuine question, as I'm currently implementing an R7RS Scheme interpreter in Haskell and was wondering this before I just went with IORefs.)
- tome 12y agoA variable that is mutable to Scheme doesn't need to be implemented as mutable in Haskell. Simulate mutable state in the usual way by passing the "before" state into functions and the "after" state out.
- tpush 12y agoHow would that work to model mutable closures? During the evaluation of a Scheme lambda expression, the current environment needs to be captured somehow. Assuming the resulting value of the evaluated lambda expression is something like (Haskell pseudocode): (env, (Env -> [Value] -> Cont -> IO ())) where 'env' is the captured environment. Further assuming this tuple is stored in the environment, how would you propagate a change to 'env' without it being an IORef and using writeIORef?
- tome 12y agoIf you have many references to mutable closures I guess indeed it would be simplest to use IORefs or STRefs. However, you can simulate most of the functionality of IORefs and STRefs using a state monad so it is possible to avoid them, at least theoretically.
- jerf 12y agoYou end up with something more like Env -> [Value] -> Cont -> IO (Env, Value) Immutability in functional programming is better understood as "the only time something can change is when a function is being called, which can be passed new arguments", rather than "nothing can ever change". This means that things can't change within the execution of a function. So when you produce the new Env, you pass it along to the next opcode's implementation, and it is just as if the Env changed from the point of view of the next opcode implementation. It just didn't change uncontrollably. Whereas an imperative program works with a lot of loops, I imagine a functional program as passing through endless, endless stack frames, like https://youtu.be/77f0Yj9uMRA?t=2m5s https://youtu.be/77f0Yj9uMRA?t=2m5s . Stack frames, endless stack frames being created. (Tail-call optimization is often cited as important to avoid blowing out the stack. It's also important just for sheer performance, so we're not literally making calls for every function call, i.e., pushing registers and state.) Haskell plays immutability to the hilt, as laziness is very difficult to imagine without it. Most other languages with immutability should probably instead have Rust-style mutation control, in my opinion, as it maintains almost all of the interesting properties of immutability in strict languages while being easier to program with, and easier to make high performance.
- bitL 12y agoDon't forget to make a Prolog as well. 48h should be sufficient as well ;-)
- rasur 12y agoUse the html version, not the pdf that is available - the pdf has (or at least did recently) errors which will throw the unwary (of course, if you enjoy learning and working out the errors, go for it...). Otherwise this is an extremely useful and informative book, and you will learn a lot about Haskell (possibly even Scheme too)
- wldlyinaccurate 12y agoIf you have never touched Haskell before, I would recommend reading the first 4 chapters of Learn You a Haskell[0] first. LYAH has a much more gentle introduction to Haskell, and really helped me grasp the basics. After those chapters I would highly recommend working through Write Youself a Scheme, using LYAH as a reference when you need a more in-depth explanation of something. This is how I taught myself Haskell, but I realise that this approach might not work for everybody -- YMMV. [0] http://learnyouahaskell.com/chapters http://learnyouahaskell.com/chapters
- airza 12y agofor some reason the URL is messed up; remove the slash at the very end.
- chrisdew 12y agoHas anyone merged Haskell and Scheme, such that I can write strongly typed Haskell code with the (lack of) Scheme syntax, and its macros? (I hope that Template Haskell would make this possible.)
- S4M 12y agoThere is Shen[0]that has Haskell's type system with Lisp syntax, but I don't think it's much used - I haven't tried it myself. [0] http://shenlanguage.org/ http://shenlanguage.org/
- pseudonom- 12y ago> Haskell's type system Shen's type system is probably better described just as expressive. http://shenlanguage.org/learn-shen/types/types_sequent_calculus.html http://shenlanguage.org/learn-shen/types/types_sequent_calcu... gives a sense of the flavor.
- S4M 12y agoThanks for the link. Out of interest, have you play with Shen yourself? Did you build something with it?
- pseudonom- 12y agoI've only messed around in the REPL. https://www.youtube.com/watch?v=lMcRBdSdO_U https://www.youtube.com/watch?v=lMcRBdSdO_U gives a fairly practical introduction.
- beering 12y agoThere is Typed Racket, which is not Haskell but still pretty cool.
- Moyamo 12y agoI've heard of something called Liskell and Lisk (two different projects). I haven't tried either of them, so I don't know if they are usable.
- akavel 12y agoDoes anybody know of a good free Haskell tutorial where the theme is "writing a game"?