我团队中的任何人都可以通过SSH连接到我们的特殊部署服务器,并从那里运行Ansible playbook将新代码推送到计算机.
如果两个人试图同时进行部署,我们会担心会发生什么.我们想要这样做,以便如果其他人正在运行它,剧本将会失败.
有关如何做到这一点的任何建议?标准解决方案是使用pid文件,但Ansible没有内置支持.
我有一个TH重文件,编译大约需要30秒.我可以使用哪些技术来帮助调试Template Haskell的性能?
我有一个程序.
import Control.Monad
import Control.Monad.Identity
import Control.Monad.Trans.Maybe
import System.Environment
tryR :: Monad m => ([a] -> MaybeT m [a]) -> ([a] -> m [a])
tryR f x = do
m <- runMaybeT (f x)
case m of
Just t -> return t
Nothing -> return x
check :: MonadPlus m => Int -> m Int
check x = if x `mod` 2 == 0 then return (x `div` 2) else mzero
foo :: MonadPlus m => [Int] -> m [Int] …Run Code Online (Sandbox Code Playgroud) 请考虑以下代码:
data (:+:) f g a = Inl (f a) | Inr (g a)
data A
data B
data Foo l where
Foo :: Foo A
data Bar l where
Bar :: Bar B
type Sig = Foo :+: Bar
fun :: Sig B -> Int
fun (Inr Bar) = 1
Run Code Online (Sandbox Code Playgroud)
尽管有趣是一场详尽的比赛,但在使用-Wall进行编译时,GHC会抱怨丢失案例.但是,如果我添加另一个构造函数:
data (:+:) f g a = Inl (f a) | Inr (g a)
data A
data B
data Foo l where
Foo :: Foo A
Baz …Run Code Online (Sandbox Code Playgroud) 在SML中,使用currying和pattern匹配来定义函数是很常见的.这是一个简单的例子:
fun zip [] _ = []
| zip _ [] = []
| zip (x::xs) (y::ys) = (x,y)::(zip xs ys)
Run Code Online (Sandbox Code Playgroud)
忽略库函数,将此端口移植到OCaml的最佳方法是什么?据我所知,没有简单的方法来使用currying和pattern匹配声明一个函数.
考虑以下代码:
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE UndecidableInstances #-}
module Foo where
class Foo a
class SomeClass a
instance {-# OVERLAPPABLE #-} (Foo a) => SomeClass a
bar :: (SomeClass a) => a -> Int
bar = const 0
foo :: (SomeClass a) => a -> Int
foo t = let x = bar t in x
Run Code Online (Sandbox Code Playgroud)
在这里,foo调用bar,并且应该能够SomeClass在其上下文中使用约束.相反,GHC假定它必须使用Foo a => SomeClass a实例:
Foo.hs:16:17:
Could not deduce (Foo a) …Run Code Online (Sandbox Code Playgroud) 请考虑以下代码
data Foo f where
Foo :: Foo Int
class DynFoo t where
dynFoo :: Foo f -> Foo t
instance DynFoo Int where
dynFoo Foo = Foo
obsFoo :: (DynFoo t) => Foo f -> Foo t
obsFoo = dynFoo
useDynFoo :: Foo f -> Int
useDynFoo (obsFoo -> Foo) = 1
Run Code Online (Sandbox Code Playgroud)
模式匹配useDynFoo应限制使用obsFoo类型Foo f -> Foo Int,这应该使它搜索一个实例DynFoo Int.但是,它会搜索DynFoo t未知的实例t,并自然会失败.
No instance for (DynFoo t0) arising from a …Run Code Online (Sandbox Code Playgroud) 似乎很多限制因素汇集在一起.让我们抽象出来.
type MonadNumState a m = (MonadState a m, Num a)
Run Code Online (Sandbox Code Playgroud)
MonadNumState它只是一个约束同义词,所以我在每次使用时都能获得函数依赖的好处,并且可以轻松地将其MonadNumState a m放入上下文中.现在,假设我希望将其抽象为约束族:
class Iterator t where
type MonadIter t a m :: Constraint
next :: (MonadIter t a m) => m t
...
instance Iterator Foo where
type MonadIter Foo a m = (MonadState a m, Num a)
...
instance Iterator Bar where
type MonadIter Bar a m = (MonadRandom m, MonadSplit a m, RandomGen a)
...
Run Code Online (Sandbox Code Playgroud)
但现在a不是功能依赖.next实际上几乎无法使用,因为a无法推断.我能做什么?当然,我可以使用类型系列代替.MonadState …
参数化类型变量很不错,但它不能扩展.作为可能发生的事情的一个例子,http://oleg.fi/gists/posts/2017-04-26-indexed-poptics.html给出了一个包含9个类型变量的抽象.我一直致力于程序转换的框架,这些框架由编程语言参数化,并且可以想象将来会有数十个或数百个参数.
所以这里是基本问题:我有一个数据类型T,它通过N种类型进行参数化.如何在T上编写函数,而不是每次使用时都写下N型变量?
以下是我看过的一些方法,其中没有一个是可以满足的:
参数化类型的变量类型 * -> *
data V = Var1 | Var2 | Var3 | Var4
myfunc :: forall (v :: V -> *). Constraints v => v Var1 -> v Var2
myfunc = ...
Run Code Online (Sandbox Code Playgroud)
所以,现在,Var1, Var2, Var3, Var4我只需要参数化一种类型的变量,而不是参数化超过4种类型的变量V -> *.
这是有效的,除了在这个例子中,myfunc因为v无法推断而无法调用.您需要将其更改为Proxy v -> v Var1 -> v Var2.然后,每次要使用myfunc差异变量时,您都需要使用自己的样板定义单独的GADT.像这样的东西:
data MyV a where
MyVar1 :: Int -> MyV Var1
MyVar2 :: String -> MyV …Run Code Online (Sandbox Code Playgroud) 这是一个非常有用的课程:
class Foo f a where
foo :: f a
Run Code Online (Sandbox Code Playgroud)
它让我为很多类型制作默认值.事实上,我甚至可能不需要知道它是什么a.
instance Foo Maybe a where
foo = Nothing
Run Code Online (Sandbox Code Playgroud)
现在我有一个Maybe a为所有人a,我可以在以后专门.
specialize :: (forall a. f a) -> f Int
specialize x = x
fooMaybe :: Maybe Int
fooMaybe = specialize foo
Run Code Online (Sandbox Code Playgroud)
嗯......这fooMaybe看起来确实非常具体.让我们看看我是否可以使用上下文来概括它:
fooAll :: (Foo f a) => f Int
fooAll = specialize foo
Run Code Online (Sandbox Code Playgroud)
哎呀!可能不会.
Foo.hs:18:21:
Could not deduce (Foo * f a1) arising from a use of `foo'
from the …Run Code Online (Sandbox Code Playgroud) haskell ×8
typeclass ×4
ghc ×3
gadt ×2
types ×2
ansible ×1
memory ×1
ocaml ×1
performance ×1
polymorphism ×1