Are there any tutorials (preferably in Haskell) about implementing a simple statically typed language?
We all know about "Write your own Scheme in 48 hours", but what about a similar tutorial for implementing a simple typechecker? I think it would be interesting to see what it's like actually implementing a real type system.submitted by SkoomaMudcrab
[link] [17 comments]
When I'm writing Python, I often ask the interpreter "what can I do with x" by typing x.<tab> in IPython. Then, if something looks useful, I'll verify that it does what I want by typing x.example_fn? and reading the documentation that comes up. If the function does what I need, I'll type y = x.example_fn(...) and repeat the process with y.
This works great for the following use cases:
- Learning to use a library
- Quickly hacking together automation scripts
Is there a way to mimic this workflow in Haskell? The closest I've found is checking the type of a variable, then querying Hoogle for functions involving that type.
Edit: A partial solution is to view the type (with :t), then see what type classes are implemented for the type (with :i). However, that doesn't help with discovering functions not defined in a type class.submitted by sharewa
[link] [18 comments]
Hey guys, after reading LYAH and some more tutorials I've decided to write my first program in Haskell. It's a very simple Uno game and buggy, but it works and coding it was fun, although there's a function which I'm very discontent with: gameRound which handles a single round (i.e. ask player which card to play, play this card, update the Game accordingly).
Coming from an imperative language (Python, C++), I would do something likewhile not game.over(): player = game.next() if game.skip: game.skip = False continue move = player.getMove() if move == DRAW: move = player.getMove() elif ...: ... card = move.card player.removeCard(card) game.topCard = card
here, the game state is updated in little pieces, e.g. by game.next(), player.removeCard(...) and later settings may override previous variables (like move). The same function in Haskell took me about 80 lines, looks bad and has quite some repetition in it (e.g. topCard = card in every case). Additionally, to update a player's hand I have to construct a whole new Game. I know that some of that burden is because my data representation is bad, but generally, what's the best way to express a pattern like this in Haskell?submitted by Dunj3
[link] [14 comments]