我试图将Haskell源的STG表示提取为Stringvia Outputable,但看起来像是coreToStgArgs在使用以下转储进行混乱:
user@machine ~/Desktop/hue $ runhaskell test.hs
[foo :: forall a. Num a => a -> a
[GblId, Arity=2, Caf=NoCafRefs, Str=DmdType] =
\r srt:SRT:[] [$dNum a1] + $dNum a1 a1;,
bar :: Int -> Int
[GblId,test.hs: test.hs: panic! (the 'impossible' happened)
(GHC version 7.10.3 for x86_64-unknown-linux):
coreToStgArgs I# 3
Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug
Run Code Online (Sandbox Code Playgroud)
这是FooBar.hs我要提取的文件:
module FooBar where
foo a = a + a
bar :: Int -> Int
bar …Run Code Online (Sandbox Code Playgroud) 我为Core Haskell编写了一个定制漂亮的打印机,以便更好地研究Core的结构.这个漂亮的打印机的要点是它需要一个CoreModule并在输出中包含数据构造函数,默认Outputable实现似乎没有.
这是我运行漂亮的打印机的模块的代码:
module Bar2 where
add :: Int -> Int -> Int
add a b = a + b
add2 a b = a + b
Run Code Online (Sandbox Code Playgroud)
这是漂亮的打印机输出:
------------------------------- Module Metadata --------------------------------
Module { "main" :: modulePackageId, "Bar2" :: moduleName }
-------------------------------- Type Bindings ---------------------------------
[r0 :-> Identifier ‘add’, rjH :-> Identifier ‘add2’]
-------------------------------- Core Bindings ---------------------------------
NonRec (Id "add2")
(Lam (TyVar "a")
(Lam (Id "$dNum")
(Lam (Id "a1")
(Lam (Id "b")
(App (App (App (App …Run Code Online (Sandbox Code Playgroud) 我有一个看起来像这样的功能
transition :: State -> ([State], [State])
Run Code Online (Sandbox Code Playgroud)
鉴于我的问题的特定领域,我知道如何将两个连续的transition函数调用链接在一起,如下所示:
transition `chain` trainsition ... `chain` transition
Run Code Online (Sandbox Code Playgroud)
不过,我想表达这种Monoid并执行与链接<>和mappend.不幸的是,我似乎无法使用以下或类似的变体来工作:
instance Monoid (State -> ([State], [State])) where
mempty = ...
mappend = ...
Run Code Online (Sandbox Code Playgroud)
返回的错误如下:
• Illegal instance declaration for
‘Monoid (State -> ([State], [State]))’
(All instance types must be of the form (T a1 ... an)
where a1 ... an are *distinct type variables*,
and each type variable appears at most once in the instance head.
Use …Run Code Online (Sandbox Code Playgroud) 我是Haskell的新手.我有类似的东西
var1::Int
var1 = 1;
if var1
then // call some fumction
else // call some other function
Run Code Online (Sandbox Code Playgroud)
在Haskell中这样做的方法是什么?我正在做的是根据变量的值调用不同的函数var(注意它是一个Int).var1只能采取1或0作为价值观.请注意,我不能在我的条件下使用bool.