我在Windows Server 2008 R2计算机上全新安装了Python 3.3.4.我已成功在全球范围内安装了最新版本的Setuptools,Pip和Virtualenv:
python ez_setup.py
easy_install pip
pip install virtualenv
Run Code Online (Sandbox Code Playgroud)
现在,当我尝试使用virtualenv ENV以下方式设置virtualenv时,我得到以下堆栈跟踪:
New python executable in ENV\Scripts\python.exe
Installing setuptools, pip...
Complete output from command [path redacted]\ENV\Scripts\python.exe -c "import sys, pip; sys...d\"] + sys.argv[1:]))" setuptools pip:
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named 'pip'
----------------------------------------
...Installing setuptools, pip...done.
Traceback (most recent call last):
File "C:\Python33\lib\runpy.py", line 160, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "C:\Python33\lib\runpy.py", line 73, in _run_code …Run Code Online (Sandbox Code Playgroud) 以下两段代码看起来非常相似.但是必须有一些差异,我希望有人可以指出它们.
data Animal = Cat | Dog
speak :: Animal -> String
speak Cat = "meowh"
speak Dog = "wouf"
Run Code Online (Sandbox Code Playgroud)
和
data Animal = Animal { speak :: String }
cat = Animal { speak = "meowh"}
dog = Animal { speak = "wouf" }
Run Code Online (Sandbox Code Playgroud) 我刚刚开始自学Haskell.这段代码应该进行素数分解:
divides :: Integer -> Integer -> Bool
divides small big = (big `mod` small == 0)
lowestDivisor :: Integer -> Integer
lowestDivisor n = lowestDivisorHelper 2 n
where lowestDivisorHelper m n
| (m `divides` n) = m -- these should belong to lowestDivisorHelper
| otherwise = lowestDivisorHelper (m+1) n
primeFactors :: Integer -> [Integer]
primeFactors 1 = []
primeFactors n
| n < 1 = error "Must be positive"
| otherwise = let m = lowestDivisor n
in m:primeFactors …Run Code Online (Sandbox Code Playgroud) 在data和type关键字总是让我困惑.
我想知道它们之间的区别data和type使用方法之间的区别.
我跑ipython qtconsole.我想执行一个我在编辑器中单独编辑的文件.当我在编辑器中对文件进行更改并使用以下命令在IPython中重新运行它时:
%run myfile.py
Run Code Online (Sandbox Code Playgroud)
代码未更新.但是,如果我ipython从终端正常运行,那么这很好.我试着autoreload在QT控制台中使用:
%load_ext autoreload
%autoreload
Run Code Online (Sandbox Code Playgroud)
但它并没有解决问题.这有什么不对?
我在lambda演算中对这个名称的类型进行了参数表示:
{-# LANGUAGE DeriveFunctor #-}
data Lambda a = Var a | App (Lambda a) (Lambda a) | Lam a (Lambda a)
deriving Functor
Run Code Online (Sandbox Code Playgroud)
我想知道是否Lambda可以成为monad的一个实例?我认为以下内容可能适用于以下内容join:
joinT :: Lambda (Lambda a) -> Lambda a
joinT (Var a) = a
joinT (fun `App` arg) = joinT fun `App` joinT arg
joinT (Lam n body) = ?
Run Code Online (Sandbox Code Playgroud)
对于第三种情况,我完全没有线索...但它应该是可能的 - 这个无名的lambda术语表示,取自De Bruijn Notation作为嵌套数据类型,是Monad的一个实例(Maybe用于区分绑定和自由这个表示中的变量):
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE DeriveFunctor #-}
data Expr a
= V …Run Code Online (Sandbox Code Playgroud) 作为一个学习练习,我试图在Haskell中实现一个heapsort.我认为Statemonad将是这样做的正确选择,因为堆积很大程度上依赖于在单个结构内部移动数据(并且do符号将是有用的).此外,我希望能够巩固我对monad的理解.
在这些示例State单子在了解你的Haskell(和数量的其他 教程),说的是State被定义为:
newtype State s a = State { runState :: s -> (a,s) }
Run Code Online (Sandbox Code Playgroud)
我应该将类型的函数s -> (a,s)(可能在其他参数中,也可能不在其他参数中)传递给State值构造函数.所以我的函数看起来像这样:
pop :: Ord a => State (Heap a) a
pop = State pop'
pop' :: Ord a => Heap a -> (a, Heap a)
-- implementation of pop' goes here
push :: Ord a => a -> State (Heap a) () …Run Code Online (Sandbox Code Playgroud) 我看到有人在讨论Scrap Your Boilerplate和Haskell中的泛型编程.这些术语是什么意思?我什么时候想要使用Scrap Your Boilerplate,我该如何使用它?
haskell functional-programming generic-programming scrap-your-boilerplate
我有一个类型系列,它确定某些东西是否属于类型级列表的头部.
type family AtHead x xs where
AtHead x (x ': xs) = True
AtHead y (x ': xs) = False
Run Code Online (Sandbox Code Playgroud)
我想构造这个结果的单例代表.这适用于简单类型的列表.
data Booly b where
Truey :: Booly True
Falsey :: Booly False
test1 :: Booly (AtHead Char [Char, Int])
test1 = Truey
test2 :: Booly (AtHead Int [Char, Int])
test2 = Falsey
Run Code Online (Sandbox Code Playgroud)
但我真正想要做的是为索引的成员列表构造此值data family.(实际上,我试图ID根据类型从异构的s 列表中投射元素.)
data family ID a
data User = User
newtype instance ID User = UserId Int
Run Code Online (Sandbox Code Playgroud)
当ID …
把我的脚趾浸入依赖类型的水域,我在规范的"静态类型长度列表"示例中有一个裂缝.
{-# LANGUAGE DataKinds, GADTs, KindSignatures #-}
-- a kind declaration
data Nat = Z | S Nat
data SafeList :: (Nat -> * -> *) where
Nil :: SafeList Z a
Cons :: a -> SafeList n a -> SafeList (S n) a
-- the type signature ensures that the input list has at least one element
safeHead :: SafeList (S n) a -> a
safeHead (Cons x xs) = x
Run Code Online (Sandbox Code Playgroud)
这似乎有效:
ghci> :t Cons 5 (Cons 3 Nil) …Run Code Online (Sandbox Code Playgroud) haskell ×8
python ×2
importerror ×1
ipython ×1
keyword ×1
lambda ×1
monads ×1
parse-error ×1
pip ×1
qt ×1
state-monad ×1
virtualenv ×1
where-clause ×1