鉴于:
data Foo =
FooString String
…
class Fooable a where --(is this a good way to name this?)
toFoo :: a -> Foo
Run Code Online (Sandbox Code Playgroud)
我想做String
一个实例Fooable
:
instance Fooable String where
toFoo = FooString
Run Code Online (Sandbox Code Playgroud)
然后GHC抱怨:
Illegal instance declaration for `Fooable String'
(All instance types must be of the form (T t1 ... tn)
where T is not a synonym.
Use -XTypeSynonymInstances if you want to disable this.)
In the instance declaration for `Fooable String'
Run Code Online (Sandbox Code Playgroud)
如果相反我使用[Char]
: …
我希望我的cabalised程序有一个--version
开关.
我希望它报告与.cabal文件中存在的版本相同的版本.
如果我必须在我的Haskell源代码和.cabal文件中单独更新版本号,我最终会使它们不同步.
那么,我的程序如何在cabal下编译,从.cabal文件中获取其版本号?
这是一个.cabal文件:
Name: myprogram
Version: 0.1
-- blah blah blah
Cabal-version: >=1.9.2
Executable myprogram
HS-source-dirs: src
Main-is: Main.hs
Build-depends: attoparsec == 0.10.*,
base == 4.3.*,
-- long long list of packages
Test-Suite test
HS-source-dirs: test, src
Type: exitcode-stdio-1.0
Main-is: Main.hs
Build-depends: attoparsec == 0.10.*,
base == 4.3.*,
-- long long list of packages
QuickCheck == 2.4.*
Run Code Online (Sandbox Code Playgroud)
有没有什么办法可以用"与可执行文件相同,加上QuickCheck"替换测试套件的长编译依赖包列表?
编辑:版本信息.
我已经启用了重载字符串,但我无法让它们工作:
$ cat overloadedstrings.hs
{-# LANGUAGE OverloadedStrings #-}
import qualified Data.ByteString as B
import qualified Data.ByteString.Lazy as BL
lazy :: BL.ByteString
lazy = "I'm a lazy ByteString"
strict :: B.ByteString
strict = "I'm a strict ByteString"
$ ghci
GHCi, version 6.12.1: 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> :l overloadedstrings.hs
[1 of 1] Compiling Main ( overloadedstrings.hs, interpreted )
overloadedstrings.hs:7:7:
No …
Run Code Online (Sandbox Code Playgroud) Haskell中的FlexibleInstances有什么问题?为什么他们不包含在Haskell 2010中?FlexibleInstances的实现是不是足够稳定以包含在标准中,还是与FlexibleInstances相关的更深层关注?使用它们是否安全?他们可能会被纳入Haskell Prime吗?
我有一个字符串数组.将它变成一组不可变的字符串的最佳方法是什么?
我认为这是一个单一的方法调用,但我在scala文档中找不到它.
我正在使用scala 2.8.1.
该哈斯克尔维基断言
MonadPlus的实例需要满足几个规则,就像Monad的实例需要满足三个monad定律一样.......最重要的是mzero和mplus形成一个幺半群.
其结果是mplus
必须是联想的.该哈斯克尔维基同意.
然而,Oleg在他的众多回溯搜索实现之一中写道
-- Generally speaking, mplus is not associative. It better not be,
-- since associative and non-commutative mplus makes the search
-- strategy incomplete.
Run Code Online (Sandbox Code Playgroud)
定义非关联是否是犹太教mplus
?MonadPlus
如果mplus
不是关联的话,前两个链接非常清楚地表明你没有真实的实例.但是,如果奥列格确实它...(在另一方面,在该文件中,他只是定义调用的函数mplus
,而并没有说这 mplus
是mplus
的MonadPlus
,他选择了一个非常令人迷惑的名字,如果这是正确的解释.)
任何人都可以推荐使用以下选项解析CSV文件的方法:
我确实尝试过Text.CSV,但它非常简单,并且缺少大部分上述功能.是否有一些更高级的CSV解析模块或者我必须"从头开始"编写它,即使用Text.ParserCombinators?我不打算重新发明轮子.
照顾自己.
我想在标准数组包中实现类似于有界数组的东西,但是使用了数组.
实现这一目标的好方法是什么?
这是我尝试过的,但必须有一个比检查边界的自定义函数中包装所有内容更好的方法:
import Data.Array.Repa
data C = A | F | L deriving (Eq,Enum,Ord,Bounded,Show)
data Ballot c = Ballot {
vote::Array U (Z :. Int) Int
} deriving Show
mkBallot::(Eq c ,Enum c,Ord c, Bounded c, Show c) => c -> Ballot c
mkBallot c = Ballot $ fromListUnboxed (Z :. max) (genSc c)
where
max = (fromEnum (maxBound `asTypeOf` c)) + 1
genSc::(Eq c,Enum c,Ord c,Bounded c,Show c) => c -> [Int]
genSc c = [ f x …
Run Code Online (Sandbox Code Playgroud) Control.Monad.List.ListT的文档声明它"除非参数monad是可交换的,否则不会产生monad".
我怎样才能知道monad是否可交换?是否存在CommutativeMonad类型类?应该有吗?
特别是,Control.Monad.RWS.Lazy.RWS是一个可交换的monad?