Building in-memory

11 views
Skip to first unread message

bcc...@gmail.com

unread,
Mar 27, 2020, 3:13:40 PM3/27/20
to Shake build system
hello,

I want to build an in-memory data-structure that tracks changes in
source files (think of something like an LSP server that tracks
changes in source code, builds some kind of data-structure and can then
answer questions about it). My current approach has shake writing the
data processed from a source file to a target file; when the program
is invoked it reads all target files, joins the data (they have a
Monoid instance), and returns something.

I want to make the program work like a server instead (so that I forgo
all the needless I/O), with shake being called to update an in-memory
data-structure. I can write empty target files to satisfy shake if
needed, and thought of using the State monad to modify the in-memory
data-structure; but I'm struggling with something related to
https://github.com/ndmitchell/shake/issues/572; couldn't shake's (the
function) signature be |Monoid a => ShakeOptions -> Rules a -> IO a|?
But I guess what I really want to know is the best way to do what I
want (i.e., using shake to update an in-memory datastructure)… Should
I be using IORef or …?

thank you,

-- bruno

Neil Mitchell

unread,
Mar 31, 2020, 5:05:55 PM3/31/20
to bcc...@gmail.com, Shake build system
Hi Bruno,

The Ghcide project does something quite similar to what you are describing - see https://github.com/digital-asset/ghcide. There's also a presentation and video me of talking about how it works, including some details on Shake: https://ndmitchell.com/#ghcide_7_sep_2019

You probably want to use the Database module https://hackage.haskell.org/package/shake-0.18.5/docs/Development-Shake-Database.html and specify `/dev/null` as the shakeFiles field - with that, you can stop doing all IO. Using shakeRunDatabase you pass in a set of Action a -> IO a, which should be what you need. The idea is that your rules are fixed, but the actions vary, which is why its not Rules a -> IO a.

Let me know if those things are what you were looking for.

Thanks, Neil

--
You received this message because you are subscribed to the Google Groups "Shake build system" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shake-build-sys...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/shake-build-system/8135a8a0-faa1-4d21-8411-466b21f82f43%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages