I have the following two similar function definitions:
left f (Left x) = Left (f x)
left _ (Right x) = Right x
left' f (Left x) = Left (f x)
left' _ r@(Right _) = r
Run Code Online (Sandbox Code Playgroud)
When I check the type signatures of the two functions, I am confused by the following types:
ghci> :t left
left :: (t -> a) -> Either t b -> Either a b
ghci> :t left'
left' :: (a -> a) -> Either …Run Code Online (Sandbox Code Playgroud) 我正在学习带有箭头Arrow的教程编程。我已经根据论文输入了以下代码,除了的SF定义是由data,而不是论文中所定义的newtype(实际上,由于我是从内存中键入代码的,所以我偶然地做了此更改):
import Control.Category
import Control.Arrow
import Prelude hiding (id, (.))
data SF a b = SF { runSF :: [a] -> [b] } -- this is the change, using data instead of newtype as in the paper
-- The folowing code is the same as in the paper
instance Category SF where
id = SF $ \x -> x
(SF f) . (SF g) = SF $ …Run Code Online (Sandbox Code Playgroud) 我编了Haskell的GUI应用程序stack-1.7.1,ghc-8.2.2,gtk+-2.24.28和glade-3.8.当我运行可执行文件时,黑色控制台窗口始终跟随GUI窗口.我想摆脱它,但我没有找到任何关于Haskell GUI应用程序的提示.我还是Haskell的新手,尤其是Haskell编译.所以我很抱歉,如果这是一项简单的任务,但如果有人能给我一些提示我很感激.
在Thinking with Types一书中,6.4 Continuation Monad讲到了类型a和forall r. (a -> r) -> r是同构的,可以通过以下函数来见证:
cont :: a -> (forall r. (a -> r) -> r)
cont x = \f -> f x
unCont :: (forall r. (a -> r) -> r) -> a
unCont f = f id
Run Code Online (Sandbox Code Playgroud)
在这本书中,它告诉我们任何具有相同基数的两种类型总是彼此同构的。所以我试图找出类型a和的基数forall r. (a -> r) -> r。
假设类型的基数a是|a|。那么对于类型forall r. (a -> r) -> r,如何计算其基数等于|a| …
我在网上搜索了解决方案,找到了一些有用的信息,如下:
以下是我的配置:
:set prompt "\ESC[33mImported Modules: %s\n\ESC[34m\x03BB> \ESC[0m"
:set prompt-cont "\ESC[31m > \ESC[0m"
Run Code Online (Sandbox Code Playgroud)
加载时ghci,不起作用(见下面的截图)
看来只有第一个 ASCII 转义序列\ESC[33m生效,其余序列都没有渲染。
接下来我根据wiki进行如下修改:
:set prompt "\ESC[33m\STXImported Modules: %s\n\ESC[34m\STX\x03BB> \ESC[0m\STX"
:set prompt-cont "\ESC[31m\STX > \ESC[0m\STX"
Run Code Online (Sandbox Code Playgroud)
更好了,但似乎仍然只有第一个转义序列有效,而其他序列被忽略。
这次我猜测转义序列的渲染可能与转义字符有关\n,所以我\n在每个序列的末尾添加并删除,\STX如下所示:
:set prompt "\ESC[33mImported Modules: %s\n\ESC[34m\x03BB> \ESC[0m\n"
:set prompt-cont "\ESC[31m > \ESC[0m\n"
Run Code Online (Sandbox Code Playgroud)
现在它可以按预期工作,但必须引入一些额外的\n,这会导致布局丑陋。
现在我不知道为什么需要一些额外的东西\n才能在 GHCi 提示符中正确渲染转义序列以及如何解决这个问题。
感谢您提供任何信息!
finally并且onException是模块中的两个函数Control.Exception,它们具有相同的签名但行为不同.
这是文件.因为finally,它说:
finally
:: IO a -- computation to run first
-> IO b -- computation to run afterward (even if an exception was raised)
-> IO a
Run Code Online (Sandbox Code Playgroud)
虽然因为onException,它说:
喜欢
finally,但只有在计算引发异常时才执行最终操作.
所以我做了以下测试:
ghci> finally (return $ div 4 2) (putStrLn "Oops!")
Oops!
2
ghci> finally (return $ div 4 0) (putStrLn "Oops!")
Oops!
*** Exception: divide by zero
Run Code Online (Sandbox Code Playgroud)
这是按预期行事的.
但是,onException不是:
ghci> onException (return $ div 4 2) …Run Code Online (Sandbox Code Playgroud) 根据此博客,我已经美化了Powershell ,但是Operator和Parameter如下所示为灰色:
所以我通过Set-PSReadlineOption以下方式更改它们的颜色:
Set-PSReadlineOption -TokenKind Operator -ForegroundColor Yellow
Run Code Online (Sandbox Code Playgroud)
但出现以下错误:
Set-PSReadLineOption:找不到与参数名称“ TokenKind”匹配的参数?
???? ?:1 ??:22
- Set-PSReadlineOption -TokenKind运算符-ForegroundColor黄色
- CategoryInfo:InvalidArgument:(:) [Set-PSReadLineOption]?ParameterBindingException
- FullyQualifiedErrorId:NamedParameterNotFound,Microsoft.PowerShell.SetPSReadLineOption
但是显示的帮助文件Set-PSReadlineOption显示它具有一个TokenKind参数,Operator而该参数又可以作为其参数。
我很困惑为什么会发生此错误。
我的powershell版本是
感谢您的任何建议!
haskell ×6
arrows ×1
colors ×1
exception ×1
ghci ×1
glade ×1
gtk ×1
isomorphism ×1
newtype ×1
powershell ×1
prompt ×1
psreadline ×1
types ×1