yesodweb/yesod — Issue #235: SessionMap should use ByteStrings values
Author: meteficha
Created: 2012-01-24 09:47:40+00:00
State: open

Hello!

Currently we have

```haskell
type SessionMap = Map.Map Text Text
```

While this makes it easy to put text data on the session, it makes it impossible to efficiently put binary data. For example, see the code on [`yesod-auth-fb`'s `setUserAccessToken` and `getUserAccessToken` functions](https://github.com/meteficha/yesod-auth-fb/blob/b29820f075ae55a69ca85711332ea311f7c58879/src/Yesod/Auth/FB.hs#L117). We have to (a) lose time converting from `Ascii` (i.e. `ByteString`) to `Text`, (b) save the expiration time in a non-compact way using `show` and `read` and (c) use three different keys, while one should suffice using something like `cereal`.

Note that if we had

```haskell
type SessionMap = Map.Map Text ByteString
```

then it would still be quite easy to put `Text` values by using `encodeUtf8` and `decodeUtf8`. The other way around is the one that is very hard, since you can't easily create a `Text` value for every `ByteString` (you'd need to do some enconding tricks).

(I'm not proposing to use `ByteString` keys since keys usually are hardcoded so it doesn't make a lot of difference. But they could be `ByteString`s as well.)

Bottomline: using `ByteStrings` is more flexible and the only thing we lose is API compatibility.

Cheers!