我喜欢读黑色的白色.因此,在RI中可以采取以下措施:
par (bg = "black")
par (fg = "ivory1")
Run Code Online (Sandbox Code Playgroud)
我希望默认情况下设置这些选项.但是,人们不会简单地写入这些行,.Rprofile因为据我所知,在执行它时,图形设备尚未初始化.相反,正如另一个答案中所建议的那样,应该重新分配options()$device以包括必要的选项设置.我没有成功.
这是我试过的:
~/.Rprofile
f_device <- options()$device
blackdevice <- function (...) {
f_device(...)
par (bg = "black")
par (fg = "ivory1")
}
options (device = blackdevice)
Run Code Online (Sandbox Code Playgroud)
这里的想法是将原始device函数保存到另一个变量,然后从我的新device函数中调用它.我得到的是:
Error in f_device(...) : could not find function "f_device"
Run Code Online (Sandbox Code Playgroud)
- 在我跑的时候plot (something).
我的另一个想法是这样:
~/.Rprofile
.First <- function () {
options(f_device = options()$device)
blackdevice <- function (...) {
options()$f_device(...)
par (bg = …Run Code Online (Sandbox Code Playgroud) 根据Bartosz Milewski的文章(一,二),我定义了一个F代数:
(这并不是说我的代码是Bartosz思想的一个确切体现,它仅仅是我对它们的有限理解,而且任何缺陷都是我自己的.)
module Algebra where
data Expr a = Branch [a] | Leaf Int
instance Functor Expr where
fmap f (Branch xs) = Branch (fmap f xs)
fmap _ (Leaf i ) = Leaf i
newtype Fix a = Fix { unFix :: a (Fix a) }
branch = Fix . Branch
leaf = Fix . Leaf
-- | This is an example algebra.
evalSum (Branch xs) = sum xs
evalSum (Leaf i …Run Code Online (Sandbox Code Playgroud) 考虑前一个问题的这些定义:
type Algebra f a = f a -> a
cata :: Functor f => Algebra f b -> Fix f -> b
cata alg = alg . fmap (cata alg) . unFix
fixcata :: Functor f => Algebra f b -> Fix f -> b
fixcata alg = fix $ \f -> alg . fmap f . unFix
type CoAlgebra f a = a -> f a
ana :: Functor f => CoAlgebra f a -> a …Run Code Online (Sandbox Code Playgroud) 我理解CAF是一种形式,在某种意义上它在内存中具有特定的形状,或者是一种可以评估的某种值的无限多种可能的图形表示.(值得注意的是,"常量应用形式"与"静态thunk"同义.)
我理解它是不变的,因为没有自由变量,并且已经包含了评估常量形式所需的所有信息.这是一个没有向外指向箭头的形状.
但为什么" 适用 "?因此我无法入睡.每个人都说咖啡馆,咖啡馆,但实际上谁知道字面意思是什么?它是否与应用仿函数有关(我猜不是)?还有哪些其他类型的应用形式?
I am trying to put several diagrams together in a kind of a table. I think this is called "index print", photography people do that when they have to review many photographs at once. Anyway, this is the code:
main :: IO ()
main = mainWith @(Diagram B)
$ (tile . fmap renderOne) examples
renderOne :: AnyGraph -> Diagram B
renderOne (AnyGraph gr) = ...
tile :: [Diagram B] -> Diagram B
tile xs = let columns = (ceiling …Run Code Online (Sandbox Code Playgroud) stack new通常会创建一个默认Setup.hs文件.我从一个项目中删除了它,它仍然适用于任何lts解析器lts-2.它cabal check至少也通过了cabal版本1.24.(虽然不是cabal 1.22.)
我可以从这个结果中得出结论,包括Setup.hs项目中的默认值不再流行了,我可以放弃它吗?特别是,将许多潜在用户从安装,如果它不经过包装改行cabal check了cabal 1.22?
PS这个问题比其他问题更具体,类似于我想知道的问题,具体来说,如果由于缺少其他不必要而导致cabal check某个版本没有通过的软件包在某些情况下将被计入该软件包,并且考虑到Haskell生态系统的当前状态,是否在项目中没有任何其他缺点.无论是必要的或有用的总体这里不是问题.cabalSetup.hsSetup.hsSetup.hs
呈现本身往往越式安全正在通过引入的模式newtype是项目的值(或多个值)的newtype包装,做一些操作,然后收回投影.一个无处不在的例子是Sum和Product幺半群:
? x + y = getSum $ Sum x `mappend` Sum y
? 1 + 2
3
Run Code Online (Sandbox Code Playgroud)
我想象可以为每个函数自动推出一系列函数,如withSum,withSum2等等newtype.或者也许Identity可以创建参数化,以供使用ApplicativeDo.或许还有其他一些我无法想到的方法.
我想知道是否有一些现有技术或理论.
PS 我不满意coerce,原因有两个:
安全 我认为它不是很安全.在被指出它实际上是安全的之后,我尝试了一些事情并且我无法做任何有害的事情,因为它有可能存在模糊性时需要类型注释.例如:
? newtype F = F Int deriving Show
? newtype G = G Int deriving Show
? coerce . (mappend (1 :: Sum Int)) . coerce $ F 1 :: G
G …Run Code Online (Sandbox Code Playgroud)今天我想知道有多少素数符合这个范围Word8,但这个最微不足道的任务给了我一个意想不到的...... 没有结果.
? import Data.Numbers.Primes
? import Data.Word
? takeWhile (<= (maxBound :: Word8)) primes
[2,3,5,7,11,13,17,19,23,25,29,31,35,37,41,43,47,49,53,55,59,61,71,73,
77,79,83,85,89,95,97,101,103,107,109,115,119,121,125,127,133,137,139,
145,149,151,157,161,163,167,173,175,179,185,187,191,197,199,203,205,
209,215,217,223,235^CInterrupted.
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,此评估不仅不会终止,而且所产生的数字也不是全部!
我继续围着这个案子跳舞:
? maxBound :: Word8
255
? takeWhile (<= 255) primes
[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,
97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181
,191,193,197,199,211,223,227,229,233,239,241,251]
? takeWhile (<= (maxBound :: Word8)) [1..]
[1,2,3, {- ..., -} 253,254,255]
-- This of course works, so I do not present the consecutive
-- natural numbers inbetween 3 and 253.
? takeWhile (<= 255) $ take 255 primes
[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,
97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181
,191,193,197,199,211,223,227,229,233,239,241,251]
? …Run Code Online (Sandbox Code Playgroud) 请考虑以下代码段:
class D u a where printD :: u -> a -> String
instance D a a where printD _ _ = "Same type instance."
instance {-# overlapping #-} D u (f x) where printD _ _ = "Instance with a type constructor."
Run Code Online (Sandbox Code Playgroud)
这就是它的工作原理:
? printD 1 'a'
...
...No instance for (D Integer Char)...
...
? printD 1 1
"Same type instance."
? printD [1] [1]
...
...Overlapping instances for D [Integer] [Integer]
...
? printD [1] ['a'] …Run Code Online (Sandbox Code Playgroud) 考虑以下代码:
{-# language FlexibleInstances, UndecidableInstances #-}
module Y where
class C m where
x :: m
instance {-# overlappable #-} Monoid m => C m where
x = mempty
instance C Int where
x = 53
Run Code Online (Sandbox Code Playgroud)
什么是x?
? :type x
x :: C m => m
Run Code Online (Sandbox Code Playgroud)
到目前为止,一切都很好。现在删除Int实例。什么是x?
? :type x
x :: Monoid m => m
Run Code Online (Sandbox Code Playgroud)
惊喜!
为什么会这样呢?
haskell ×9
typeclass ×2
benchmarking ×1
cabal ×1
coerce ×1
newtype ×1
optimization ×1
performance ×1
r ×1
recursion ×1