Effective Haskell Chapter 11
@RebeccaSkinner
In Effective Haskell Chapter 11 (~ p 410 in ePub), when creating the Encode and Decode instances for String, pack and unpack are used, but given all the imports, ghci couldn’t resolve them so I needed to use the qualified names, BC.pack and BC.unpack.
Serializing FileMode (approx p. 413 in ePub) doesn’t work on Macs since CMode wraps a Word16, not Word32. I was baffled because the documentation on Hackage said CMode wraps a Word32, not realizing that the Hackage docs were probably generated on a Linux box. I ended up writing the encoding/decoding for Word16 so GHC could pick the right one.
When defining Encode to have encode and encodeWithSize (approx p 415 in ePub), the MINIMAL pragma is missing the # at the opening ( {-
instead of {-#
)
I assume there was some refactoring going on because the FileData type was defined with record fields: fileName, fileSize, filePermissions, and fileData, but the Encode instance uses packedFileName, packedFileSize, packedFilePermissions, and packedFileData.
The file pack example is a fun one for getting at these different data encodings.
Popular Pragprog topics










Other popular topics










Latest in Pragprog
Latest (all)
Categories:
My Saved Portals
-
None saved yet
Popular Portals
- /elixir
- /opensuse
- /rust
- /kotlin
- /ruby
- /erlang
- /python
- /clojure
- /react
- /quarkus
- /go
- /vapor
- /v
- /react-native
- /wasm
- /security
- /django
- /nodejs
- /centos
- /haskell
- /rails
- /fable
- /gleam
- /swift
- /js
- /deno
- /assemblyscript
- /tailwind
- /laravel
- /symfony
- /phoenix
- /crystal
- /typescript
- /debian
- /adonisjs
- /julia
- /arch-linux
- /svelte
- /spring
- /preact
- /flutter
- /c-plus-plus
- /actix
- /java
- /angular
- /ocaml
- /zig
- /kubuntu
- /scala
- /zotonic
- /vim
- /rocky
- /lisp
- /html
- /keyboards
- /vuejs
- /nim
- /emacs
- /nerves
- /elm