是的,这些:
{-#LANGUAGE TypeOperators, RankNTypes #-}
import Control.Morphism.Zygo
import Control.Morphism.Prepro
import Control.Morphism.Histo
import Control.Functor.Algebra
import Control.Functor.Extras
import Control.Functor.Fix
import Control.Comonad.Cofree
zygohistomorphic_prepromorphism
:: Functor f
=> Algebra f b
-> GAlgebra f (ZygoT (Cofree f) b) a
-> (f :~> f)
-> FixF f
-> a
zygohistomorphic_prepromorphism f
= g_prepro (distZygoT (liftAlgebra f) (distHisto id))
Run Code Online (Sandbox Code Playgroud)
是的,我知道他们是(HHOS)的笑话.我正在寻找一个简单的黑客价值的真实世界的例子,最后,但并非最不重要的是,将它添加到维基说"这是表达XYZ的惯用方式".如果你没有提出解决方案,我会对此表示赏心悦目.如果你完全迷失了他们的意思,爱德华在reddit上发布了一个简短的解释.
符合条件的答案必须:
至少做一些远程的,理论上计算上有用的东西.也就是说,减少的答案id已经消失.
使用该方案的所有功能,不传入id,const或等效.
不能用简单的香草褶皱等表达,所以不要仅仅product以蜿蜒的方式实施.
奖励积分将给予:
众所周知的问题或算法
解决,分别表达,以一种不寻常的方式获得
清晰度和/或性能
和/或黑客价值
和/或lulz,大致按此顺序,以及
高级答案(耶和华民主)
请注意爱德华的答案如下.您使用的ZHPM实施是您的选择.
我遇到了让GHC专门化一个具有类约束的函数的问题.我有我的问题就在这里的一个小例子:Foo.hs和 Main.hs.这两个文件编译(GHC 7.6.2,ghc -O3 Main)并运行.
注意:
Foo.hs真的被剥离了.如果您想了解为什么需要约束,可以在这里看到更多代码.如果我将代码放在一个文件中或进行许多其他微小的更改,GHC只是简单地将调用内联到plusFastCyc.这不会发生在实际代码中,因为plusFastCycGHC内联太大,即使在标记时也是如此INLINE.关键是要专门调用plusFastCyc,而不是内联它.plusFastCyc在真实代码的许多地方被调用,所以即使我可以强迫GHC这样做,也不可能复制这么大的功能.
感兴趣的代码是plusFastCycin Foo.hs,在这里转载:
{-# INLINEABLE plusFastCyc #-}
{-# SPECIALIZE plusFastCyc ::
forall m . (Factored m Int) =>
(FastCyc (VT U.Vector m) Int) ->
(FastCyc (VT U.Vector m) Int) ->
(FastCyc (VT U.Vector m) Int) #-}
-- Although the next specialization makes `fcTest` fast,
-- it isn't useful to me in …Run Code Online (Sandbox Code Playgroud) 是否有一种在Haskell中拆分字符串的标准方法?
lines和words上一个空格或换行从拆分工作的伟大,但肯定没有拆就一个逗号一个标准的方式?
我在Hoogle上找不到它.
具体来说,我正在寻找split "," "my,comma,separated,list"回报的东西["my","comma","separated","list"].
首先,我正在阅读的真实世界Haskell表示永远不会使用foldl而是使用foldl'.所以我相信它.
但我对什么时候使用foldrvs. 朦胧foldl'.虽然我可以看到他们如何以不同的方式摆放在我面前的结构,但是当"哪个更好"时,我太愚蠢了.我想在我看来似乎并不重要,因为它们都产生相同的答案(不是吗?).事实上,我以前使用这个结构的经验来自Ruby inject和Clojure reduce,它们似乎没有"左"和"右"版本.(附带问题:他们使用哪个版本?)
任何有助于像我这样的智能挑战的洞察力都会非常感激!
似乎newtype定义只是data遵循某些限制的定义(例如,只有一个构造函数),并且由于这些限制,运行时系统可以newtype更有效地处理s.并且未定义值的模式匹配处理略有不同.
但是假设Haskell只知道data定义,没有newtypes:编译器不能自己发现给定的数据定义是否遵守这些限制,并自动更有效地对待它?
我确定我错过了什么,必须有更深层次的理由.
我正在尝试定义任何跨越ghci中多行的简单函数,以下面的示例为例:
let abs n | n >= 0 = n
| otherwise = -n
Run Code Online (Sandbox Code Playgroud)
到目前为止,我已尝试在第一行后按Enter键:
Prelude> let abs n | n >= 0 = n
Prelude> | otherwise = -n
<interactive>:1:0: parse error on input `|'
Run Code Online (Sandbox Code Playgroud)
我也尝试过使用:{和:}命令但是我没有做到这一点:
Prelude> :{
unknown command ':{'
use :? for help.
Run Code Online (Sandbox Code Playgroud)
我在Linux上使用GHC Interactive版本6.6 for Haskell 98,我缺少什么?
有一个简单的答案:为什么GHC这么大?
对于"如果Haskell是正确的工具,为什么我不应该关心大小"的传福音不感兴趣; 这是一个技术问题.
我将数据类型定义为:
data ComitteeView = CommitteeView { committeeId :: CommitteeId
, committeeMembers :: [Person]
}
data CommitteesView = CommitteesView { committeeView :: [CommitteeView] }
Run Code Online (Sandbox Code Playgroud)
现在,就目前而言,我将Persistent模型定义为:
Person
name Text
Committee
name Text
CommitteePerson
personId PersonId
committeeId CommitteeId
Run Code Online (Sandbox Code Playgroud)
我可以很容易地使用Esqueleto创建一个填充委员会视图的查询.它会是这样的:
getCommitteeView cid =
CommitteeView <$> runDB $
select $
from (person `InnerJoin` pxc `InnerJoin` committee) -> do
on (committee ^. CommitteeId ==. pxc ^. CommitteePersonCommitteeId)
on (person ^. PersonId ==. pxc ^. CommitteePersonPersonId)
where_ (committee ^. CommitteePersonCommitteeId ==. val cid)
return person
Run Code Online (Sandbox Code Playgroud)
现在,考虑填充问题CommitteesView …
我正在尝试使用ghc-modvim插件进行类型/语法检查等.但是,我发现ghc-mod总是在错误消息中使用完整的类型路径,例如:
test.hs|71 col 13 error| Couldn't match type ‘Data.Text.Internal.Text’
|| with ‘[GHC.Types.Char]’
|| Expected type: containers-0.5.6.2:Data.Map.Base.Map
|| [GHC.Types.Char]
|| ([(integer-gmp-1.0.0.0:GHC.Integer.Type.Integer,
|| integer-gmp-1.0.0.0:GHC.Integer.Type.Integer)],
|| containers-0.5.6.2:Data.Set.Base.Set
|| integer-gmp-1.0.0.0:GHC.Integer.Type.Integer)
|| Actual type: containers-0.5.6.2:Data.Map.Base.Map
|| Data.Text.Internal.Text
|| ([(integer-gmp-1.0.0.0:GHC.Integer.Type.Integer,
|| integer-gmp-1.0.0.0:GHC.Integer.Type.Integer)],
|| containers-0.5.6.2:Data.Set.Base.Set
|| integer-gmp-1.0.0.0:GHC.Integer.Type.Integer)
|| In the second argument of ‘containers-0.5.6.2:Data.Map.Base.map’, namely
|| ‘zippedMap’
|| In the second argument of ‘(GHC.Base.$)’, namely
|| ‘containers-0.5.6.2:Data.Map.Base.map
...
Run Code Online (Sandbox Code Playgroud)
这会使屏幕变得杂乱,我很难找出哪里出了问题.作为比较,这是使用以下内容的同一文件的错误消息ghci:
test.hs:71:13:
Couldn't match type ‘T.Text’ with ‘[Char]’
Expected type: M.Map [Char] ([(Integer, …Run Code Online (Sandbox Code Playgroud)