Compiling Haskell School of Expression's source code

Yeah, if anybody knows a similar more recent book then that would be great. But, I don’t think there are many Haskell books that focus on graphics and interactive programs. I still think the book is worth it to try and update the code. I also think we’re pretty close, because it already seems to work on Linux. I’ll spend some more time searching for the problem.

@edamiani can you try resizing the window that opens when you run Picture.main? Does that change anything?

EDIT: The problem might also be that it doesn’t use a shader, which is technically undefined behavior. I’ll try adding a simple shader.

EDIT: I have now implemented shaders: https://github.com/noughtmare/haskell-school-of-expression/commit/ebd55d49daf07f16208f15389e4c3d7a51c6943b. The scaling is not perfect yet, but this should allow us to see if the lack of a shader was the problem.

@jaror Resizing did the trick, so maybe a screen refresh should be enforced?

I also tested resizing the screen in the book’s example and it worked.

That’s great to hear, I will roll back the shader changes and add a change that forces a resize at the start of the program (EDIT: done). I should also note that I haven’t implemented text rendering yet, so that’s the next thing I will try to fix.

2 Likes

Worked perfectly, thanks!

And thank you for all the time and effort spent here, it’s really appreciated.

I’ll keep an eye on your repo for the text fix! :slight_smile:

1 Like

I have made text work! (only works for the first 128 unicode characters but that should be enough for the examples in the book)

It requires a stack build before you can run any examples with stack, because that copies the font file to the right directory. An example with text is Animation.main2 which shows the time since the start of the program.

EDIT: Now the text is white.

1 Like

That was fast! :grin:

Thanks again! I will pull the changes and start playing around with it. :slight_smile:

Hello I’m new to haskell and I’m trying to write and compile the book’s code but I can’t manage to make it work. I’m using stack and using OpenGL and GLFW-b and I’m trying to use your SOE module but it gives this error :

SimpleGraphics> configure (lib + exe)
Configuring SimpleGraphics-0.1.0.0…
SimpleGraphics> build (lib + exe)
Preprocessing library for SimpleGraphics-0.1.0.0…
Building library for SimpleGraphics-0.1.0.0…
[5 of 6] Compiling SOE.FreeType

/home/luca/SimpleGraphics/src/SOE/FreeType.hs:10:1: error:
Could not find module ‘Paths_SOE’
Use -v (or :set -v in ghci) to see a list of the files searched for.
|
10 | import Paths_SOE
| ^^^^^^^^^^^^^^^^^^^^^^^^^^

– While building package SimpleGraphics-0.1.0.0 (scroll up to its section to see the error) using:
/home/luca/.stack/setup-exe-cache/x86_64-linux-tinfo6/Cabal-simple_mPHDZzAJ_3.2.1.0_ghc-8.10.4 --builddir=.stack-work/dist/x86_64-linux-tinfo6/Cabal-3.2.1.0 build lib:SimpleGraphics exe:SimpleGraphics-exe --ghc-options " -fdiagnostics-color=always"
Process exited with code: ExitFailure 1

Can someone help me understand what I’m doing wrong and how to use your modules.

Which command did you use to build it? You should use cabal (maybe stack works too) and not ghc directly, because that Paths_SOE module is generated by cabal.

Edit: Wait, I see now that you are using stack, so that shouldn’t be the problem. But for some reason the package you are compiling is called SimpleGraphics. Did you just take that one file and copied it to a new project? That won’t work without some changes.

In that case, you need to change is the import of Paths_SOE and its usage on line 40. You can replace that use site with a file path of a file containing the font you want to use. Or use your own data-files: replace Paths_SOE with Paths_<your package name>, see this relevant section in the cabal guide.

A better option might be to fetch my library from GitHub via stack. See this FAQ: https://docs.haskellstack.org/en/stable/faq/#i-need-to-use-a-package-or-version-of-a-package-that-is-not-available-on-hackage-what-should-i-do. So this should work:

extra-deps:
  - git: https://github.com/noughtmare/haskell-school-of-expression.git
    commit: ffe612387120e67e0d57591f58557518fc9e6913

I managed to solve my problems. I got to chapter 19 and I can’t manage to draw the coins (everything else seems to work). What could be wrong?

I’ve fixed the coins issue