问题
Title pretty much says it all. I'm looking for something like this:
f :: Int -> Bool -> Int
f = _body
Djinn can use theorem proving to generate code for such a function by proving that the type is inhabited.
I'm wondering, is there an existing way to get this functionality from within Emacs? So instead of writing TemplateHaskell in my code, I just run a command on my code and it inserts the generated code?
I have ghc-mod installed, but I'm not very familiar with it.
回答1:
Quoting the relevant part of Serras emacs guide:
This is nice, but in some cases ghc-mod can do even more for you: it can write your whole expression! It does so by leveraging the power of Djinn. For example, let's go back to the definition of maybeMap after splitting:
maybeMap Nothing f = _maybeMap_body
maybeMap (Just x) f = _maybeMap_body
If you press C-c C-a in each of the holes, several options for the code to be written there will be shown, including Nothing in the first case, and Nothing and Just x in the second case. You just need to select the code you want to include from a list, and it will be automatically completed. Note that this functionality becomes very handy when you need to work with expressions involving currying and tupling, because it takes care of obtaining a correctly-typed expression for you.
So, yes using Djinn you can write whole expressions in some cases. I haven't personally used them but it seems to be possible in Emacs.
来源:https://stackoverflow.com/questions/28386749/is-there-a-way-to-use-djinn-to-auto-generate-haskell-code-in-emacs