小编me2*_*me2的帖子

iOS检测截图?

App Store上的应用程序Snapchat是一款应用程序,可让您在其上分享带有自毁功能的图片.您只能查看X秒的照片.如果您在使用家用电源键组合显示图片时尝试截取屏幕截图,它会告诉发件人您尝试截取屏幕截图.

SDK的哪个部分可以让您检测到用户正在截取屏幕截图?我不知道这是可能的.

screenshot ios

128
推荐指数
4
解决办法
9万
查看次数

让Haskell的hsenv在Ubuntu 13上工作

我正在努力GHC开发Ubuntu.做了以下事情:

sudo apt-get install ghc
sudo apt-get install cabal-install
cabal update
cabal install hsenv
Run Code Online (Sandbox Code Playgroud)

然后我尝试创建一个hsenv环境并得到以下内容:

xx@xx-VirtualBox:~/scm/t1$ hsenv
Creating Virtual Haskell directory structure
Installing GHC
Initializing GHC Package database at /home/xx/scm/t1/.hsenv/ghc_pkg_db
Copying necessary packages from original GHC package database
  Failed to copy optional package ghc-binary from system's GHC: 
    /usr/bin/ghc-pkg process failed with status 1
  Using user-wide (~/.cabal/packages) Hackage download cache directory
Installing cabal config at /home/xx/scm/t1/.hsenv/cabal/config
Installing activate script
Installing cabal wrapper using /home/xx/scm/t1/.hsenv/cabal/config at /home/xx/scm/t1/.hsenv/bin/cabal
Skipping …
Run Code Online (Sandbox Code Playgroud)

ubuntu sudo haskell

37
推荐指数
1
解决办法
766
查看次数

自由Monad的推导

Control.Monad.Free 实现一个免费的monad:

data Free f a = Pure a | Free (f (Free f a))

instance Functor f => Functor (Free f) where
  fmap f = go where
    go (Pure a)  = Pure (f a)
    go (Free fa) = Free (go <$> fa)
Run Code Online (Sandbox Code Playgroud)

我在理解第二go行时遇到了很多麻烦,特别是在描述自由monad是什么的情况下.有些人可以描述一下这是如何工作的以及为什么它会成为Free f a一个免费的monad?

monads haskell

11
推荐指数
2
解决办法
448
查看次数

使用"派生"时模板Haskell错误

与我得到的结果有点混淆.使用以下内容:

GHCi, version 7.4.2: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Prelude> :m + Language.Haskell.TH
Run Code Online (Sandbox Code Playgroud)

我得到了这个成功的结果:

Prelude Language.Haskell.TH> runQ [d| data X = X |]
[DataD [] X_0 [] [NormalC X_1 []] []]
Run Code Online (Sandbox Code Playgroud)

但我得到这个错误:

Prelude Language.Haskell.TH> runQ [d| data X = X deriving Show |]

<interactive>:4:30:
    The exact Name `X' is not in scope
      Probable cause: you used a unique name (NameU) …
Run Code Online (Sandbox Code Playgroud)

haskell template-haskell

7
推荐指数
1
解决办法
158
查看次数

模板Haskell:GHC阶段限制以及如何克服

我在模块中有以下代码:

{-# LANGUAGE TemplateHaskell #-}

module Alpha where

import Language.Haskell.TH
import Data.List

data Alpha = Alpha { name :: String, value :: Int } deriving (Show)
findName n = find ((== n) . name)

findx obj = sequence [valD pat bod []]
    where
        nam = name obj
        pat = varP (mkName $ "find" ++ nam)
        bod = normalB [| findName nam |]
Run Code Online (Sandbox Code Playgroud)

然后我在主文件中有以下内容:

{-# LANGUAGE TemplateHaskell #-}

import Alpha

one   = Alpha "One" 1
two   = Alpha "Two" 2
three …
Run Code Online (Sandbox Code Playgroud)

haskell template-haskell

7
推荐指数
1
解决办法
1254
查看次数

Haskell无限类型

我正在努力让下面的代码工作.它是一个有限状态机,我传入一个函数作为下一个状态.调用该函数r并返回结果列表+下一个函数作为下一个状态.继续调用直到列表用完,并返回结果的串联.monad是一个错误monad,允许我在需要时抛出错误.

fsm f []     = return []
fsm f (r:rs) = do
    (xs, f') <- f r
    rest     <- fsm f' rs
    return $ xs ++ rest
Run Code Online (Sandbox Code Playgroud)

错误是:

Occurs check: cannot construct the infinite type: t1 = t0 -> m0 ([a0], t1)
In the first argument of `fsm', namely f'
Run Code Online (Sandbox Code Playgroud)

我之前看过无限类型错误,我理解它的方法是用a包装一个类型newtype.但我无法弄清楚如何完成这项工作.

有人能指出洞察力吗?

haskell types

5
推荐指数
1
解决办法
392
查看次数

Haskell Variadic函数和实例声明

我试图理解这个关于可变函数的问题的例子,并尝试修改代码:

class SumRes r where 
    sumOf :: Integer -> r

instance SumRes Integer where
    sumOf = id

instance (Integral a, SumRes r) => SumRes (a -> r) where
    sumOf x = sumOf . (x +) . toInteger
Run Code Online (Sandbox Code Playgroud)

对此:

class SumRes r where 
    sumOf :: Int -> r

instance SumRes Int where
    sumOf = id

instance (SumRes r) => SumRes (Int -> r) where
    sumOf x = sumOf . (x +) 
Run Code Online (Sandbox Code Playgroud)

我得到了Illegal instance declaration for SumRes …

haskell types

3
推荐指数
1
解决办法
180
查看次数

为什么Haskell没有概括某些函数

我在文件中有以下内容:

import Control.Monad
ema a = scanl1 $ \m n -> (1-a)*m + a*n
macd  = ema 9 . uncurry (zipWith (-)) . liftM2 (,) (ema 26) (ema 12)
Run Code Online (Sandbox Code Playgroud)

在编译时,我得到以下内容:

:t macd
macd :: [Integer] -> [Integer]
Run Code Online (Sandbox Code Playgroud)

然而,

:t ema 9 . uncurry (zipWith (-)) . liftM2 (,) (ema 26) (ema 12)
ema 9 . uncurry (zipWith (-)) . liftM2 (,) (ema 26) (ema 12)
  :: Num a => [a] -> [a]
Run Code Online (Sandbox Code Playgroud)

那么,为什么在更受限制的类型中存在差异macd呢?

haskell types

3
推荐指数
1
解决办法
165
查看次数

搜索get =但不是==的正确VIM正则表达式是什么?

在以下代码中:

a = b = c == 1
Run Code Online (Sandbox Code Playgroud)

我想只匹配前两个=,而不是最后的==.

我认为该模式\<=\>将起作用,因为\<匹配开头的单词并\>匹配结束.但事实并非如此.这种模式有什么问题,正确的模式是什么?

regex vim

2
推荐指数
1
解决办法
88
查看次数

Haskell:为什么RealFrac并不意味着分数?

注意:完整的源代码在这里:https://gist.github.com/anonymous/7085509

我有以下功能:

tournament n p pop = do
    winner <- (\w -> min (n - 1) (floor (log w / log (1-p)))) <$> gaRandom
    (flip S.index) winner <$> S.sort <$> seqChoose n pop
Run Code Online (Sandbox Code Playgroud)

没有类型签名,编译器告诉我tournament签名是:

tournament
  :: (Floating a, Ord a1, RealFrac a, Random a) =>
     Int -> a -> S.Seq a1 -> StateT GA Data.Functor.Identity.Identity a1
Run Code Online (Sandbox Code Playgroud)

哪个看起来很好.但是当我使用它时:

t2 = do
    g <- newStdGen
    let a = evalState (tournament 5 0.9 (S.fromList [1..10])) (GA g)
    return …
Run Code Online (Sandbox Code Playgroud)

haskell types

2
推荐指数
1
解决办法
1061
查看次数

标签 统计

haskell ×8

types ×4

template-haskell ×2

ios ×1

monads ×1

regex ×1

screenshot ×1

sudo ×1

ubuntu ×1

vim ×1