我正在尝试在Ubuntu 14.04上安装PureScript.我有最新版本的Haskell-Platform并且已经运行了cabal update.在cabal install purescript我收到一个错误,说System.IO.UTF8没有找到该模块.谷歌搜索显示,这utf8-string是安装该软件包时暴露模块的一部分,应该是其中一个.
但是,当我安装它时,没有这样的包可用:
ely@eschaton:~$ cabal update
Downloading the latest package list from hackage.haskell.org
ely@eschaton:~$ cabal --reinstall install utf8-string
Resolving dependencies...
In order, the following will be installed:
utf8-string-1 (reinstall)
Warning: Note that reinstalls are always dangerous. Continuing anyway...
Configuring utf8-string-1...
Building utf8-string-1...
Preprocessing library utf8-string-1...
[1 of 5] Compiling Codec.Binary.UTF8.String ( Codec/Binary/UTF8/String.hs, dist/build/Codec/Binary/UTF8/String.o )
[2 of 5] Compiling Codec.Binary.UTF8.Generic ( Codec/Binary/UTF8/Generic.hs, dist/build/Codec/Binary/UTF8/Generic.o )
[3 …Run Code Online (Sandbox Code Playgroud) 我是Purescript(以及Haskell)的新手,我遇到了一个无法统一的错误.最初我有:
newtype Domain = Domain String
newtype Keyword = Keyword String
type Result = {
domain :: Domain,
occurred :: Boolean,
position :: Number,
quality :: Number
}
is_min_pos :: Maybe Result -> Maybe Result -> Maybe Result
is_min_pos Nothing Nothing = Nothing
is_min_pos Nothing y = y
is_min_pos x Nothing = x
is_min_pos x y = if y.position < x.position then y else x
Run Code Online (Sandbox Code Playgroud)
这给了我错误
Cannot unify type
Prim.Object
with type
Data.Maybe.Maybe
Run Code Online (Sandbox Code Playgroud)
我以为是因为期待x和y是Maybe Record类型.所以要明确我将代码改为,按类型进行模式匹配.
data Result = Result { …Run Code Online (Sandbox Code Playgroud) 我一直在尝试使用rank-2类型在PureScript中编码GADT,如此处针对Haskell所述
我的代码看起来像:
data Z
data S n
data List a n
= Nil (Z -> n)
| Cons forall m. a (List a m) (S m -> n)
fw :: forall f a. (Functor f) => (forall b . (a -> b) -> f b) -> f a
fw f = f id
bw :: forall f a. (Functor f) => f a -> (forall b . (a -> b) -> f b)
bw x f = map …Run Code Online (Sandbox Code Playgroud) 是否可以在Purescript中对类型构造函数设置某些约束?例如:
newtype Name = Name String
-- where length of String is > 5
Run Code Online (Sandbox Code Playgroud) Haskell有所述Integral,其包括类型类Integer,Int,Int32,Int64,Natural,等.
Purescript中是否有类似的类型类?
在定义了以下简单的树结构之后
data Tree a = Leaf | Branch (Tree a) a (Tree a)
Run Code Online (Sandbox Code Playgroud)
我尝试Foldable为它定义一个实例,只定义foldMap和使用foldrDefault和foldlDefault函数:
instance treeFoldableInstance :: Foldable Tree where
foldr = foldrDefault
foldl = foldlDefault
foldMap f Leaf = mempty
foldMap f (Branch left a right) = foldMap f left <> (f a) <> foldMap f right
Run Code Online (Sandbox Code Playgroud)
然而,这会导致:
The value of treeFoldableInstance is undefined here, so this reference is not allowed.
Run Code Online (Sandbox Code Playgroud)
当我定义foldl并foldr明确地,它编译.这个错误的文档告诉我有关懒惰的信息,但这在哪里适用?
我的项目目前有编译器错误,但这不应该阻止我打开交互式PureScript会话,但它确实:
$ pulp psci
Error found:
at /Users/srid/code/PS/Pallanguzhi/src/Board.purs line 41, column 50 - line 41, column 50
Unable to parse module:
[..]
See https://github.com/purescript/purescript/wiki/Error-Code-ErrorParsingModule for more information,
or to contribute content related to this error.
Run Code Online (Sandbox Code Playgroud)
无论项目状态如何,我如何启动psci shell?我不关心无法导入项目模块; 只需要一个裸壳.
有没有办法在PureScript中模拟未知长度的匹配数组?作为一个例子,这是我如何List在Haskell中使用它:
addFirstTwo :: (Num a) => [a] -> a
addFirstTwo (x:y:_) = x + y
Run Code Online (Sandbox Code Playgroud)
我在PureScript中尝试了类似的东西(使用Array a而不是[a]),但是出现了以下错误:
运算符Data.Array.(:)不能在模式中使用,因为它是函数Data.Array.cons的别名.只能在模式中使用数据构造函数的别名.
我知道我可以List在PureScript中使用s而不是Arrays,但我想将模式与数组匹配.在阅读PureScript by Example的Array模式匹配部分后,我没有看到如何执行此操作.
如果这是一个愚蠢的问题,请耐心等待.如何键入一个带有两个记录并返回其公共字段数组的泛型函数?
比方说我有:
type A = { name :: String, color :: String }
type B = { name :: String, address :: Address, color :: String }
myImaginaryFunction :: ???
-- should return ["name", "color"] :: Array of [name color]
Run Code Online (Sandbox Code Playgroud)
我想编写一个函数,它接受任何两种类型的记录并返回一个公共字段数组.一个haskell解决方案也可以工作.
问题:我有许多常见字段的不同记录类型.我如何"包含"记录类型定义中的公共字段?
例:
newtype RecordType1 = RecordType1 { a :: Int, b :: Int, y :: String }
newtype RecordType2 = RecordType2 { a :: Int, b :: Int, z :: Boolean }
Run Code Online (Sandbox Code Playgroud)
如何在PureScript中编写等效的?
newtype RecordType1 = RecordType1 { CommonFields, y :: String }
newtype RecordType2 = RecordType2 { CommonFields, z :: Boolean }
Run Code Online (Sandbox Code Playgroud)
" PureScript类型系统概述"中Union提到的类型类可能是我所寻求的......但它似乎是自PureScript 0.12.0以来的.
有什么建议?有什么我想念的吗?
谢谢!