小编Ber*_*ian的帖子

无法安装 GHC-Mod

大家好,我正在尝试为 vscode 安装 ghc-mod,但我遇到了这个问题:

**$ stack install ghc-mod**
Populated index cache.

Error: While constructing the build plan, the following exceptions were encountered:

In the dependencies for ghc-mod-5.8.0.0:
    Cabal-2.0.1.1 from stack configuration does not match >=1.18 && <1.25 (latest matching version
                  is 1.24.2.0)
    base-4.10.1.0 from stack configuration does not match >=4.6.0.1 && <4.10  (latest matching
                  version is 4.9.1.0)
    mcabal-helper must match <0.8 && >=0.7.3.0, but the stack configuration has no specified version
                 (latest matching version is 0.7.3.0)
    extra-1.6.8 from stack configuration …
Run Code Online (Sandbox Code Playgroud)

haskell ghc-mod haskell-stack

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

控制台应用程序在生成时不会生成可执行文件

您好,我无法从我的项目(.NET Core 2.1控制台应用程序)生成可执行文件。我已经检查了输出文件,输出类型为控制台应用程序。它构建成功(程序可以正常运行),但是没有可执行文件。

我曾与调试和释放的尝试都和我已经调查bin\obj\文件夹为可执行文件却是没有。
这是我的Bin的样子:

在此处输入图片说明

我调查了一下Properties->Application,一切都设置好了,但仍然没有可执行文件。

.net executable build

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

如何使用带有警卫的尾递归将列表拆分为两个

如果我有一个列表让我们说[1,2,3,4],我怎么能创建一个两个列表的元组,第一个列表包含奇数元素,第二个列表包含偶数元素.我怎么能这样做会尾随 - 递归?例如.

    Input  : [1,2,3,4]
    Output : ([1,3],[2,4]) with tail recursion and not ranges. [|x<-...]
Run Code Online (Sandbox Code Playgroud)

到目前为止,我尝试过类似的东西:

sumt::[Int]->([Int],[Int])
sumt []=([],[])
sumt (x:xs)
    | x `mod` 2==0 = x: (fst $ tupl xs)
    | otherwise    = x: (snd $ tupl xs) where 
    tupl []=([],[])
    tupl (y:ys)=y:(tupl ys)   //how can i put the condition here ? I need it 
                            //to be aware of both guard cases at each iteration
Run Code Online (Sandbox Code Playgroud)

我基本上需要两个由每个保护案例组成的本地列表,最后它们放在一个元组中.

haskell tuples list-comprehension

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

也许是将null附加到列表的替代方法

我试图从列表中只提取奇数位置的元素.我知道Data.List中有特定的方法,但我是新的,我试图通过重新发明轮子来学习.

到目前为止,我已经尝试过这种方法,我正在分支内部方法

manF::[Int]->[Int]
manF []=[]
manF ls=go ls [] 0 where 
        go [] nl _ = nl
        go (x:xs) rez cnt=if cnt `mod`2 ==0 then go xs (x:rez) (cnt+1) else go xs rez (cnt+1)
Run Code Online (Sandbox Code Playgroud)

但我必须在最后扭转这一结果.

有没有更多的原子然后使用也许来处理null的

所以,如果我在运算符的左侧移动if子句,cons我可以返回什么而不是null?我没有尝试过,没有成功.

manF::[Int]->[Int]
manF []=[]
manF ls=go ls [] 0 where 
        go [] nl _ = nl
        go (x:xs) rez cnt=if cnt `mod`2 ==0 then x else *(something?!)* : go xs rez (cnt+1)
Run Code Online (Sandbox Code Playgroud)

haskell list

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

类型类实例中的类型类约束

你好,从Real World Haskell书中做的例子我遇到了这个例子,我无法理解它的意思和它是如何工作的:
instance Num a=>Num (SymbolicManip a)
在这种情况下,我应该转换为类似的东西:"对于Num类型的实例,SymbolicManip有一个约束关于它的类型领域a,是:a作为Num本身的一个实例"?有人可以告诉我,如果我解释正确或解释?
为什么instance Num (SymbolicManip a)不够?

-- The "operators" that we're going to support
data Op = Plus | Minus | Mul | Div | Pow
        deriving (Eq, Show)

{- The core symbolic manipulation type -}
data SymbolicManip a = 
          Number a           -- Simple number, such as 5
        | Arith Op (SymbolicManip a) (SymbolicManip a)
          deriving (Eq, Show)

{- SymbolicManip will be an instance of …
Run Code Online (Sandbox Code Playgroud)

haskell typeclass

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

如何从不纯的方法返回纯值

我知道它听起来一定是微不足道的,但我想知道如何从仿函数中展开一个值并将其作为纯值返回?

我试过了:

f::IO a->a
f x=(x>>=) 

f= >>=
Run Code Online (Sandbox Code Playgroud)

我应该在右侧放置什么?我不能使用,return因为它会再次包裹它.

monads haskell functor

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

如何使用javascript下载文件?

您好,我希望能够在按下按钮时下载给定的文件。该文件将通过电话提供。api目前,我将其保存在本地存储中。所以我的文件夹是这样的:

rootFolder
-js file
-html file
-download file (`sample.csv`)
Run Code Online (Sandbox Code Playgroud)

如何创建下载link?到目前为止,我已经尝试过: <a download="sample.csv"></a> 我也尝试过使用onclick事件:

<a download="sample.csv" onclick="download()"></a>

function download|(){
   .....code that calls the `api`
}
Run Code Online (Sandbox Code Playgroud)

我不知道这两种方式如何适合:the downloadapi(如果有)和click事件处理程序(如果您打算在下载时进行其他逻辑处理)。

javascript download

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

获取类型参数的标识?

我有以下类型要成为Monoidtypeclass 的实例。我不知道如何为身份设置参数化字段。使用参数化类型获取该类型的身份时有什么办法吗?

data Tree a=Leaf a | Node a (Tree a) (Tree a) |Empty deriving (Eq,Show)

instance Monoid Tree where
    mempty=Empty
    mappend a Empty=a
    mappend a b=Node (identity) x y
Run Code Online (Sandbox Code Playgroud)

如您所见,我需要将简单字段设置为参数类型的标识。

mappend::Tree Int
mappend (Leaf 1) (Leaf 2)=Node 0 (Leaf 1) (Leaf 2)

mappend::Tree []
mappend (Leaf [1,2])(Leaf [2,3])=Node [] (Leaf [1,2])(Leaf [2,3])
Run Code Online (Sandbox Code Playgroud)

haskell monoids

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

无法在IO上下文中使用状态monad

我正在尝试使用State monad进行一些计算,同时还要对其进行更改。我已经实现的情况下ApplicativeMonadFunctor以及getputmodify等我不明白的脱糖do块。您如何同时提供状态和状态转换器?

实用程序

    get::State s s
    get=State $ \s ->(s,s) 

    put::s->State s ()
    put x=State $ \_ -> ((),x)

    modify::(s->s)->State s ()
    modify f=get>>= \x -> put (f x)

    evalState::State s a->s->a
    evalState act =fst . run act

    execState::State s a->s->s
    execState act=snd.run act
Run Code Online (Sandbox Code Playgroud)

module Env where
    import State 
    import System.Directory
    import Control.Monad
    data Env=Env{
        envName::String,
        fileNames::[String]
    }
    instance Show Env where 
        show Env{envName=x,fileNames=xs} = …
Run Code Online (Sandbox Code Playgroud)

haskell state-monad

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

为什么这些列表在Erlang中不等效

我试图理解|Erlang中的用法,更具体地说为什么此表达式不等效:

[4,5,6|7]=:=[4,5,6,7]

|符号不是仅用于模式匹配,只是为了匹配列表而中断列表吗?

erlang list

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