小编scl*_*clv的帖子

Haskell无法推断出类型相等

我有以下代码,不编译:

  import Numeric.AD

  data Trainable a b = forall n . Floating n =>  Trainable ([n] -> a -> b) (a -> b -> [n] -> n) 

  trainSgdFull :: (Floating n, Ord n) => Trainable a b -> [n] -> a -> b -> [[n]]
  trainSgdFull (Trainable _ cost) init input target =  gradientDescent (cost input target) init
Run Code Online (Sandbox Code Playgroud)

我想使用Trainable类型来表示可通过梯度下降训练的机器学习系统.第一个算法是传递函数,sencond是成本函数,a是输入类型,b是输出/目标类型,列表包含可学习参数.编译器抱怨这个:

 src/MachineLearning/Training.hs:12:73:
Could not deduce (n1 ~ ad-3.3.1.1:Numeric.AD.Internal.Types.AD s n)
from the context (Floating n, Ord n)
  bound by the type signature …
Run Code Online (Sandbox Code Playgroud)

haskell automatic-differentiation

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

使用 Haskell 的数字的倍数

我编写了以下函数来查找输入数字的倍数。当我尝试给出负数时,输出只是正列表。如何修改我的代码以允许在输出中列出负数?

我的尝试:

multiples n = if n<0 then result1 else result2
where
   result1 = [x | x <- [0..], x `mod` (-n) == 0]        
   result2 = [x | x <- [0..], x `mod` n == 0]

  Input : take 5 $ multiples (-3)
  Output: [0,3,6,9,12]
  Expected Output: [0,-3,-6,-9,-12]
Run Code Online (Sandbox Code Playgroud)

haskell functional-programming

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

Haskell切片和lexing问题

这两个函数如何解析?

>  (** (1/2)) $ 40
6.324555320336759
it :: Double

>  ((**) (1/2)) $ 40
9.094947017729282e-13
it :: Double
Run Code Online (Sandbox Code Playgroud)

haskell

0
推荐指数
1
解决办法
142
查看次数

使用Haskell和Yesod激活Pandoc

我想使用Yesod和Haskell来调用Pandoc,以将某种格式转换为其他格式。

pandocConverted :: String -> IO String 
pandocConverted input = do
    (Just hIn, Just hOut, _, _) <- createProcess (proc "pandoc" []) { std_in = CreatePipe, std_out = CreatePipe }
    hPutStr hIn input    
    converted  <- hGetContents hOut
    return converted
Run Code Online (Sandbox Code Playgroud)

这很好。但是,如何翻译成其他格式?

例如,我怎么这样称呼pandoc?

pandoc -s README -o example4.tex

或这个?

pandoc -s -S -t docbook README -o example9.db

templates haskell pandoc yesod

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