examples of using fclabels or data-accessor with happstack?

8 views
Skip to first unread message

tphyahoo

unread,
Oct 7, 2009, 1:39:58 PM10/7/09
to HAppS
I wind up writing a lot of boilerplate type get/set/modify code in my
StateVersions/AppStaten.hs files.

I came accross

http://www.reddit.com/r/haskell/comments/9qmbg/playing_with_records/

and got interested in using fclabels or data-accessor with happstack,
to get around the brokenness of haskell records.

But then i came across Andrew Birkitt's post "happs state mistake"
which suggests that this isn't as simple as it sounds.

http://www.nobugs.org/blog/archives/2009/02/15/happs-state-mistake/

Is anybody out there successfully using happs state with fclabels or
data-accessor, and if so can you give feedback on gotchas and
workarounds so others can follow?

thanks, thomas.

Kamil Dworakowski

unread,
Oct 8, 2009, 7:51:46 AM10/8/09
to HAppS
I'm using them. fclabels play very well with the Conal's idea
explained here: http://conal.net/blog/posts/semantic-editor-combinators/

He proposes a general approach for defining a function that modifies
a individual element in a custom structure. A simple example is the
task of modifying the second element of a pair, slightly more
involved one is to modify the second of the second element of nested
pairs -- (y,(x, z)).

Andrew Birkett in his post [1] is talking about a limitation of
happstack state on the types of the function used to generate
transactions. One cannot parametrize this functions with combinators
created with fclabels. But this is true of any function, including
your custom defined ones.

fclabels saves you the boilerplate of writing your own modifiers and
setters. It is not a silver bullet and surely the possibility of
passing functions into the transaction would be of much higher
benefit to any happstack based project, but it at least saves the
irritation of having to write those modifiers.

Cheers,
Kamil

[1] http://www.nobugs.org/blog/archives/2009/02/15/happs-state-mistake/

Chris Eidhof

unread,
Oct 8, 2009, 9:56:21 AM10/8/09
to ha...@googlegroups.com
We designed fclabels to work in a way similar to lenses. Especially
the applicative instance should be quite useful, for example in this
way:

data User = User {name :: String, password :: String, age :: Int}

Now if you make a projection of User to UserView with the password
field removed:

data UserView = UserView {name :: String, age :: Int}

Then you can update the original user with the values in UserView if
you have built the projection using fclabels. I'm going to write some
of this up in the coming months, it'll take some time but stay tuned.

-chris
Reply all
Reply to author
Forward
0 new messages