有没有一种方法可以使用Djinn在Emacs中自动生成Haskell代码? [英] Is there a way to use Djinn to auto-generate Haskell code in Emacs?

查看:78
本文介绍了有没有一种方法可以使用Djinn在Emacs中自动生成Haskell代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标题几乎说明了一切。我正在寻找这样的东西:

Title pretty much says it all. I'm looking for something like this:

f :: Int -> Bool -> Int
f = _body

Djinn可以使用定理证明通过证明该函数生成代码

Djinn can use theorem proving to generate code for such a function by proving that the type is inhabited.

我想知道,是否有现有的方法可以从Emacs中获得此功能?因此,不是在代码中编写TemplateHaskell,而是在代码上运行命令,然后插入生成的代码?

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?

我已经安装了ghc-mod,但是我对此不太熟悉。

I have ghc-mod installed, but I'm not very familiar with it.

推荐答案

引用Serras的相关部分 emacs指南

Quoting the relevant part of Serras emacs guide:


这很好,但是在某些情况下ghc-mod可以为您做更多:
可以写下您的整个表情!它通过利用
Djinn的力量来做到这一点。例如,让我们回到
拆分后的maymap定义:

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 Nothing f = _maybeMap_body

maybeMap(Just x)f = _maybeMap_body

maybeMap (Just x) f = _maybeMap_body

如果在每个孔中按Cc Ca,则将
代码写在此处的几个选项将会显示出来,包括第一个
情况下的Nothing和第二个情况下的Nothing和Just x。您只需要
从列表中选择要包含的代码,它将自动完成
。请注意,当您需要处理涉及currying和
关联的表达式时,此功能非常方便
,因为它会为您获取正确键入的
表达式。

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.

是的,是的,使用Djinn可以在某些情况下编写整个表达式。我还没有亲自使用过它们,但是在Emacs中似乎是有可能的。

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.

这篇关于有没有一种方法可以使用Djinn在Emacs中自动生成Haskell代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆