在以下Haskell代码中:
data Cmd =
CmdExit |
CmdOther
deriving (Read, Show)
guiString2Cmd s =
(return (read s :: Cmd)) `catch` \(e :: SomeException) -> return CmdExit
Run Code Online (Sandbox Code Playgroud)
如果我做:
guiString2Cmd "CmdOther"
Run Code Online (Sandbox Code Playgroud)
一切正常.但是,如果我这样做:
guiString2Cmd "some wrong string"
Run Code Online (Sandbox Code Playgroud)
代码崩溃而不是评估为CmdExit.
如何让代码处理异常而不是崩溃?
通过直接将定义和法律翻译成Haskell,我很开心学习类别理论.Haskell当然不是Coq,但它帮助我获得了类别理论的直觉.我的问题是:以下是将一个类别的定义合理地"翻译"到Haskell中吗?
{-
The following definition of a category is adapted from "Basic Category Theory" by Jaap van Oosten:
A category is given by a collection of objects and a collection of morphisms.
Each morphism has a domain and a codomain which are objects.
One writes f:X->Y (or X -f-> Y) if X is the domain of the morphism f, and Y its codomain.
One also writes X = dom(f) and Y = cod(f)
Given two morphisms f and g such …Run Code Online (Sandbox Code Playgroud) 以下Haskell代码是一个简单的"控制台IO"DSL:
data Ap a = Ap { runAp :: ApStep a }
data ApStep a =
ApRead (String -> Ap a)
| ApReturn a
| ApWrite String (Ap a)
ioRead k = Ap $ ApRead k
ioReturn a = Ap $ ApReturn a
ioWrite s k = Ap $ ApWrite s k
ioWriteLn s = ioWrite (s ++ "\n")
apTest =
ioWriteLn "Hello world!" $
ioRead $ \i ->
ioWriteLn ("You wrote [" ++ i ++ "]") $
ioReturn 10 …Run Code Online (Sandbox Code Playgroud) 如何在没有VS 2008将文件复制到项目文件夹的情况下将现有C#文件添加到VS 2008 C#项目中?
将现有C++文件添加到C++项目时,VS 2008不会复制文件.它只是使用文件路径.