我正嘗試使用數據類型點菜方式爲模板目的定義免費monad。我寫了一些combinators,但我卡住了。我的程序不斷髮散,我不明白爲什麼。使用免費Monads發散
考慮:
math :: Math :<: f => MathExpr a -> Free f()
blank :: f :<: (Textual :+: Math) => Free f() -> Free (Blank k f)()
equals :: Free (Math :+: (Blank L Math))()
-> Free (Math :+: (Blank R Math))()
-> Free Equation()
的組合物(空白數學)具有類型:
blank . math :: (f :<: (Textual :+: Math)
, Math :<: f
) => MathExpr a -> Free (Blank k f)()
通知使得f必須同時比數學小於聯接文本和數學的,和更大的。所以f的唯一可能性就是Math。 (我不知道在我的部分更多的工作編譯器不能推斷出這一點,如果有的話)
當我試圖評估該問題發生:
test :: Free Equation()
test = (hoistFree (inj :: Blank 'L Math a -> (Math :+: Blank 'L Math) a)
. blank
. (math :: MathExpr x -> Free Math())
$ "hi"
)
`equals` (math $ "world")
這顯然循環,在100掛我的CPU %。計算結果如下:
Free (Equation (Free (DirectSum {unDirectSum = Right
在這一點上,值被截斷並且GHCi退出。所以它顯然會發現,等於的第一個參數是在直接和的後半部分,但它似乎不能計算空白。
我所有的功能都是完整的,我在這裏沒有看到底部,但我從來沒有在固定點組合器上擅長。有任何想法嗎?
編輯:有免費的單子現在該模塊是:http://lpaste.net/93471 模塊Data.Domain是:http://lpaste.net/93472
你可以把代碼放入lpaste中嗎? –
@ J.Abrahamson:編輯包含代碼。 – nomen