我有一个已转义 unicode 的文件:
blah blah blah \u2192 blah blah blah
Run Code Online (Sandbox Code Playgroud)
我想通过搜索/替换将 unicode 转义转换为实际字符:
:%s/\\u\(\d\{4}\)/\=CodePointToCharacter(submatch(1))/g
Run Code Online (Sandbox Code Playgroud)
虽然我知道如何在插入模式下将代码点转换为字符(CTRL-V u 2192对于→),但我不知道如何在 vimL 表达式中进行转换。
我是否需要编写自定义函数,或者是否有可以使用的内置函数或插件?
我正在尝试定义一个函数来检测输入的类型是否满足给定的约束:
satisfies :: (c a => a -> b) -> a -> Maybe b
-- or the more general
claim :: (c => a) -> Maybe a
Run Code Online (Sandbox Code Playgroud)
所以期望的行为是:
>>> :t satisfies @Show show
satisfies @Show show :: a -> Maybe String
>>> satisfies @Show show (0 :: Int)
Just "0"
>>> satisfies @Show show (id :: Int -> Int)
Nothing
Run Code Online (Sandbox Code Playgroud)
目标是在可能的情况下轻松定义充分利用特化的多态函数:
showAny :: a -> String
showAny (satisfies @Show show -> Just str) = str
showAny (satisfies @Typeable showType -> …Run Code Online (Sandbox Code Playgroud) 如何使用Haskell脚本解决矩阵的身份?例如,如果使用此给定类型
type Matrice a = [[a]]
identity :: Int -> Maybe (Matrice Int)
Run Code Online (Sandbox Code Playgroud)
如何返回给定大小的标识矩阵?我知道单位矩阵是一个方形矩阵,除了左上角到右下角的值都是1之外,所有值都为零.条件是,如果大小小于1,则不定义标识矩阵并返回Nothing.
所以说,例如,
Prelude > identity 5
Just [[1,0,0,0,0],[0,1,0,0,0],[0,0,1,0,0],[0,0,0,1,0],[0,0,0,0,1]]
Prelude > identity 2
Just [[1,0],[0,1]]
Run Code Online (Sandbox Code Playgroud)
我试过了
identity1 :: Int -> Int -> [Int]
identity1 a b
| a == 0 []
| b == 0 (1:identity (a-1) (-1))
| otherwise = (0:identity' (a-1) (b-1))
identity2 :: Int -> Int -> Matrice Int
identity2 a b
| b == 0 []
| otherwise = (0:identity1 (a-1) (b-1) : identity2 …Run Code Online (Sandbox Code Playgroud) 我目前正在计划创建一个基本的网络游戏,但我们决定承担使用C#客户端制作C++服务器的任务.我知道这可能是一项艰巨的任务,但我想知道是否有任何关于实现这一目标的建议.
对不起,我没有比这更多的信息了.我们刚刚开始,只是想确保在我们的时间跨度内实现这一目标.
我需要找到所有可以用字符串中的字母组成的英语单词
sentence="Ziegler's Giant Bar"
Run Code Online (Sandbox Code Playgroud)
我可以制作一系列字母
sentence.split(//)
Run Code Online (Sandbox Code Playgroud)
如何从Ruby中的句子中创建超过4500个英语单词?
[编辑]
最好将问题分成几部分:
所以我用sinatra写了一个简单的"Hello World"网站:
#!/usr/bin/env ruby
# sinatra_demo/bin/sinatra_demo
require 'rubygems'
require 'sinatra'
get "/hello" do
"Hello World!"
end
Run Code Online (Sandbox Code Playgroud)
当我运行它,它可以工作,我可以将我的浏览器发送到http:// localhost:4567/hello并获得"Hello World":
% sinatra_demo/bin/sinatra_demo
== Sinatra/1.2.6 has taken the stage on 4567 for development with backup from WEBrick
[2011-06-30 09:29:58] INFO WEBrick 1.3.1
[2011-06-30 09:29:58] INFO ruby 1.9.2 (2011-02-18) [x86_64-darwin10.7.4]
[2011-06-30 09:29:58] INFO WEBrick::HTTPServer#start: pid=73620 port=4567
127.0.0.1 - - [30/Jun/2011 09:30:10] "GET /hello HTTP/1.1" 200 12 0.0027
localhost - - [30/Jun/2011:09:30:10 EDT] "GET /hello HTTP/1.1" 200 12
- -> /hello
127.0.0.1 …Run Code Online (Sandbox Code Playgroud) 以下代码
{-# LANGUAGE TypeSynonymInstances, FlexibleInstances #-}
module Function where
import qualified Data.Vector.Unboxed as V
import Control.Monad
type Function = V.Vector Double
instance Num Function where
(+) = liftM2 (+)
(*) = liftM2 (*)
negate = fmap negate
Run Code Online (Sandbox Code Playgroud)
返回错误,如
No instance for (Monad V.Vector)
arising from a use of `liftM2'
Run Code Online (Sandbox Code Playgroud)
虽然在文档中说Vector是Monad的一个实例.
我有一些函数(charfreq,wordfreq,charcount,wordcount,parerror),我想在dataStructure中使用给定的字符串.但我怎么能这样做?我正在尝试这些和许多方式,但我得到了所有的错误.谢谢你提前.
data StrStat = StrStat { charfreq :: [( Char , Int )]
, wordfreq :: [([ Char ] , Int )]
, charcount :: Int
, wordcount :: Int
, parerror::Maybe Int
}
analyze :: [Char] -> StrStat
analyze x = StrStat { charfreq = (charfreq x) {-this line gives error-}
, wordfreq = (wordfreq x)
, charcount = (charcount x)
, wordcount = (wordcount x)
, parerror = (parerror x)
}
Run Code Online (Sandbox Code Playgroud)
错误信息是: Syntax error in input (unexpected `=') …
所以,已经有几个月了,我有点生疏,但我似乎记得Either b是一个Monad
Prelude Control.Monad Data.Either> return "Hello" :: Either String String
<interactive>:0:1:
No instance for (Monad (Either String))
arising from a use of `return'
Possible fix:
add an instance declaration for (Monad (Either String))
In the expression: return "Hello" :: Either String String
In an equation for `it':
it = return "Hello" :: Either String String
Prelude> Right "Hi" == return "Hi"
<interactive>:0:15:
No instance for (Monad (Either a0))
arising from a use of `return'
Possible fix: …Run Code Online (Sandbox Code Playgroud) 所以,我tmux在本地计算机上运行会话,但是如果我先ssh回到自己身上,我只能连接到它(或查看有关它的信息):
% tmux ls
failed to connect to server: Connection refused
% ssh localhost -t tmux ls
Password:
0: 2 windows (created Mon Nov 26 12:47:44 2012) [208x52] (attached)
Connection to localhost closed.
Run Code Online (Sandbox Code Playgroud)
这不是必须跳过的最糟糕的箍,但为什么会发生,我该如何解决?
我正在将程序从使用切换MVector Word32为STUArray Word Word32. 在我的矢量代码中,我经常unsafeMove移动矢量切片;认为这可能是memmove为了提高效率而进行包装。
case dst \xe2\x8a\x95 3 of\n src | n < src + w -> do\n let w0 = n - src\n let w\' = w - w0\n unsafeMove (slice dst w0 v) (slice src w0 v)\n if w\' <= 3\n then do\n unsafeMove (slice (n - 3) w\' v) (slice 0 w\' v)\n else do\n let w\'\' = w\' - 3\n unsafeMove (slice (n - 3) 3 …Run Code Online (Sandbox Code Playgroud) 我通过以下代码得到了我认为的缩进错误
152 -- find the first one who can refute the scenario
153 let cs = map ($scenario) [ Suspect . getWho, Room . getWhere, Weapon . getHow ]
154 let (qs,rss) = break (not . null . intersect cs . hand) ps
155 unless (null rss) $ do
156 let refuter:ss= rss
157 let valid = intersect cs $ hand refuter
158
159 (refuter, shown) <- if cheated refuter
160 -- if the refuter is a cheater, just choose …Run Code Online (Sandbox Code Playgroud) 我在Haskell中编写了以下代码:
import Data.IORef
import Control.Monad
import Control.Monad.Trans.Cont
import Control.Monad.IO.Class
fac n = do
i<-newIORef 1
f<-newIORef 1
replicateM_ n $ do
ri<-readIORef i
modifyIORef f (\x->x*ri)
modifyIORef i (+1)
readIORef f
Run Code Online (Sandbox Code Playgroud)
这是非常好的代码,它将factorial实现为命令式函数.但是replicateM_无法完全模拟真实for循环的使用.所以我尝试使用continuation创建一些东西,但我在这里失败的是我的代码:
ff = (`runContT` id) $ do
callCC $ \exit1 -> do
liftIO $ do
i<-newIORef 1
f<-newIORef 1
callCC $ \exit2 -> do
liftIO $ do
ri<-readIORef i
modifyIORef (\x->x*ri)
modifyIORef i (+1)
rri<-readIORef i
when (rri<=n) $ exit2(())
liftIO $ do
rf<-readIORef f
return rf
Run Code Online (Sandbox Code Playgroud)
你能帮我纠正我的代码吗?谢谢