Is there a way to use Djinn to auto-generate Haskell code in Emacs?

。_饼干妹妹 提交于 2019-12-10 16:09:44

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!