How do I handle clicks on a listBox in Haskells gi

I am experimenting with using Gtk and Haskell. And I got stuck. This link shows my experiments. https://github.com/bigos/my-haskell-gtk-3-tutorial/blob/master/5-layout-containers.org#edit-the-source-2 I am trying to print the index of clicked list box row. The following code gives me a type error that I do not understand. onListBoxRowSelected listbox2 (row -> putStrLn (listBoxRowGetInd

如何处理Haskells gi中的列表框点击

我正在尝试使用Gtk和Haskell。 我被卡住了。 此链接显示我的实验。 https://github.com/bigos/my-haskell-gtk-3-tutorial/blob/master/5-layout-containers.org#edit-the-source-2 我正在尝试打印点击列表框行的索引。 下面的代码给我一个我不明白的类型错误。 onListBoxRowSelected listbox2 (row -> putStrLn (listBoxRowGetIndex row)) 我需要一个例子,我可以看到有人能够正确处理listBox行上的点击事件。 错

Print empty list in Haskell

This question already has an answer here: Print empty list in Haksell 1 answer Lists in Haskell are polymorphic in their element's type and as [] contains not enough information you have to supply ghc with it by explicitly giving a type annotation [] :: [Int] for example. The error you are getting is due to the fact that the Show instance for lists is depending on the Show instance for

在Haskell中打印空列表

这个问题在这里已经有了答案: 在Haksell打印空列表1个答案 Haskell中的列表在它们的元素类型中是多态的,并且[]包含的信息不够,您必须通过明确给出类型注释[] :: [Int]来为其提供ghc。 你得到的错误是由于列表的Show实例依赖于它的元素的Show实例,以及ghc不能确定它假定ist没有这样的实例。 现在你可能会认为所有的东西都可以转换成一个String ,但是你可以想到Int -> Int并尝试 show [(+1)] 哪些不会作为Haskel

Haskell: Using the same operator on different types in a function

I'm writing a simple interpreter in Haskell. I have 3 possible variable types: bool , int and string . To avoid repetition in evaluating comparisons, I've written a function that takes 2 expressions and an operator: data Value = IntVal Integer | StringVal String | BoolVal Bool | ... evalComparison :: Ord a => Exp -> (a -> a -> Bool) -> E

Haskell:在函数的不同类型中使用相同的运算符

我正在哈斯克尔写一个简单的解释器。 我有3种可能的变量类型: bool , int和string 。 为了避免重复评估比较,我写了一个函数,它带有2个表达式和一个运算符: data Value = IntVal Integer | StringVal String | BoolVal Bool | ... evalComparison :: Ord a => Exp -> (a -> a -> Bool) -> Exp -> Result Value evalComparison expr1 op expr2 = do val1 <- eval

How do I cast from Integer to Fractional

Let's say I have the following Haskell type description: divide_by_hundred :: Integer -> IO() divide_by_hundred n = print(n/100) Why is it that when I attempt to run this through ghc I get: No instance for (Fractional Integer) arising from a use of `/' Possible fix: add an instance declaration for (Fractional Integer) In the first argument of `print', namely `(n / 100)' In the expressio

我如何从整数转换为分数

假设我有以下Haskell类型描述: divide_by_hundred :: Integer -> IO() divide_by_hundred n = print(n/100) 为什么当我试图通过ghc运行时,我得到: No instance for (Fractional Integer) arising from a use of `/' Possible fix: add an instance declaration for (Fractional Integer) In the first argument of `print', namely `(n / 100)' In the expression: print (n / 100) In an equation for `divide_by_hundr

Cycle in type synonym declarations

I want to try out Haskell type and data with the following code type Program a = Maybe a -> (Operation a, Maybe Program a) data Operation a = Read a | Write a Program follows a continuation passing style (CPS) and Nothing indicates termination. a may be instantiated with Int or something else. However, GHC complains that: main.hs:1:1: Cycle in type synonym declarations: main.hs

循环类型同义词声明

我想用下面的代码尝试Haskell type和data type Program a = Maybe a -> (Operation a, Maybe Program a) data Operation a = Read a | Write a Program遵循延续传球风格(CPS), Nothing表示终止。 a可以用Int或其他东西实例化。 但是,GHC抱怨说: main.hs:1:1: Cycle in type synonym declarations: main.hs:1:1-58: type Program a = Maybe a -> (Operation a, Maybe Progra

Why does GHC infer type of `IO b` for an application of `hSetBuffering`?

I am trying to use hSetBuffering in a Haskell program using GHC 6.10. When I try this very simple program: module Ctlc where import IO main :: () main = do hSetBuffering stdout NoBuffering return () I get a baffling error message: ctlc.hs:8:10: Couldn't match expected type `()' against inferred type `IO b' In a stmt of a 'do' expression: hSetBuffering stdout NoBuffering

为什么GHC为`hSetBuffering`的应用程序推断`IO b`的类型?

我正在尝试在使用GHC 6.10的Haskell程序中使用hSetBuffering 。 当我尝试这个非常简单的程序时: module Ctlc where import IO main :: () main = do hSetBuffering stdout NoBuffering return () 我收到一个莫名其妙的错误信息: ctlc.hs:8:10: Couldn't match expected type `()' against inferred type `IO b' In a stmt of a 'do' expression: hSetBuffering stdout NoBuffering In the expressi

How to use yesod per

I'm trying to use the cached function to prevent multiple db queries in different widgets and handlers: newtype CachedBobId key = CachedBobId { unCachedBobId :: key } deriving Typeable getBob' :: Handler BobId getBob' = do uncle <- runInputGet $ ireq textField "bobsuncle" (Entity bob _) <- runDB $ getBy404 $ UniqueBob uncle return bob getBob :: Handler BobId getBo

如何使用yesod

我试图使用cached函数来防止在不同的小部件和处理程序中的多个数据库查询: newtype CachedBobId key = CachedBobId { unCachedBobId :: key } deriving Typeable getBob' :: Handler BobId getBob' = do uncle <- runInputGet $ ireq textField "bobsuncle" (Entity bob _) <- runDB $ getBy404 $ UniqueBob uncle return bob getBob :: Handler BobId getBob = do a <- getBob' let b

ghc armv7 binary + cabal? illegal instruction

I'm trying to get up and running on the raspberry pi 2 with the recently released ghc binaries for armv7, available here: https://www.haskell.org/ghc/download_ghc_7_10_2#linux_armv7 This says it was built with debian jesse, so I've installed debian jesse on my pi2. I've installed ghc successfully - at least ghci works. But there's no cabal, and apparently ghc 7.10.2 requires

ghc armv7 binary + cabal? 非法指令

我正在尝试在最新发布的armv7的ghc二进制文件上启动和运行覆盆子pi 2,可在此处获得: https://www.haskell.org/ghc/download_ghc_7_10_2#linux_armv7 这说它是用debian jesse构建的,所以我在我的pi2上安装了debian jesse。 我已经成功安装了ghc - 至少ghci的作品。 但是没有cabal,很明显ghc 7.10.2需要cabal 1.22+。 cabal的debian版本类似于1.16(也可以安装ghc 7.6.x)。 所以我试图用bootstrap.sh脚本从源代码安

Counting change in Haskell

I came across the following solution to the DP problem of counting change: count' :: Int -> [Int] -> Int count' cents coins = aux coins !! cents where aux = foldr addCoin (1:repeat 0) where addCoin c oldlist = newlist where newlist = (take c oldlist) ++ zipWith (+) newlist (drop c oldlist) It ran much faster than my naive top-down recursive solution, and I

计算Haskell中的变化

我遇到了DP计数变化问题的以下解决方案: count' :: Int -> [Int] -> Int count' cents coins = aux coins !! cents where aux = foldr addCoin (1:repeat 0) where addCoin c oldlist = newlist where newlist = (take c oldlist) ++ zipWith (+) newlist (drop c oldlist) 它的运行速度比我的天真的自顶向下递归解决方案快得多,我仍然试图理解它。 我得到这个给出的硬币列表, aux计

why 2.9000000000000004 instead of 2.9?

This question already has an answer here: Is floating point math broken? 23 answers How do I tell ghci to not do that, and show the results of Operations on Doubles just as any other programming language (and calculator) would and just as every 15 year old would write them? Since those results are the actual results GHCI (and your standard calculator*) calculates you cannot change the inte

为什么2.9000000000000004而不是2.9?

这个问题在这里已经有了答案: 浮点数学是否被破坏? 23个答案 我如何告诉ghci不要这样做,并像其他编程语言(和计算器)一样,每两年15岁就会显示双倍操作的结果? 由于这些结果是GHCI(和标准计算器*)计算的实际结果,因此您无法更改结果的内部表示形式(请参阅TNI的答案)。 既然你只想显示一个固定的小数位数,那么它更像是一个演示文稿(与printf("%f.2",...) )。 这个解决方案可以在https://stackov