haskell

Why should we use Behavior in FRP

五迷三道 提交于 2020-01-12 07:17:27
问题 I am learning reactive-banana. In order to understand the library I have decide to implement a dummy application that would increase a counter whenever someone pushes a button. The UI library I am using is Gtk but that is not relevant for the explanation. Here is the very simple implementation that I have come up with: import Graphics.UI.Gtk import Reactive.Banana import Reactive.Banana.Frameworks makeNetworkDescription addEvent = do eClick <- fromAddHandler addEvent reactimate $ (putStrLn .

Defining function signature in GHCi

☆樱花仙子☆ 提交于 2020-01-12 07:09:16
问题 Defining a function signature in Haskell's interpreter GHCi doesn't work. Copying an example from this page: Prelude> square :: Int -> Int <interactive>:60:1: error: • No instance for (Show (Int -> Int)) arising from a use of ‘print’ (maybe you haven't applied a function to enough arguments?) • In a stmt of an interactive GHCi command: print it Prelude> square x = x * x How can I declare a function signature and then give function definition in Haskell interactively? also: why can't I simply

Defining function signature in GHCi

℡╲_俬逩灬. 提交于 2020-01-12 07:08:11
问题 Defining a function signature in Haskell's interpreter GHCi doesn't work. Copying an example from this page: Prelude> square :: Int -> Int <interactive>:60:1: error: • No instance for (Show (Int -> Int)) arising from a use of ‘print’ (maybe you haven't applied a function to enough arguments?) • In a stmt of an interactive GHCi command: print it Prelude> square x = x * x How can I declare a function signature and then give function definition in Haskell interactively? also: why can't I simply

Can I disable the “non-exhaustive pattern matches” warning only for lambdas?

ぃ、小莉子 提交于 2020-01-12 07:04:00
问题 Can I disable the non-exhaustive pattern matches warning only for lambdas? I like the warning in general, but not for actual lambda literals like this: map (\(x:xs)->...) ls I think this code makes it pretty clear that I expect all the values of ls to always have at least one element, and there is no neat way to handle the error case in the lambda. (I guess I could move the pattern match into a case statement, but that would just be ugly.) 回答1: Yes, but only in GHC 7.2 onwards; pass -fno-warn

Can I disable the “non-exhaustive pattern matches” warning only for lambdas?

て烟熏妆下的殇ゞ 提交于 2020-01-12 07:03:28
问题 Can I disable the non-exhaustive pattern matches warning only for lambdas? I like the warning in general, but not for actual lambda literals like this: map (\(x:xs)->...) ls I think this code makes it pretty clear that I expect all the values of ls to always have at least one element, and there is no neat way to handle the error case in the lambda. (I guess I could move the pattern match into a case statement, but that would just be ugly.) 回答1: Yes, but only in GHC 7.2 onwards; pass -fno-warn

Haskell cabal: I just installed packages, but now the packages are not found

强颜欢笑 提交于 2020-01-12 06:40:15
问题 Over here is the only reason I can find that packages I'm installing using cabal are not being found by GHC: This happens when you install a package globally, and the previous packages were installed locally. Note that cabal-install install locally by default [...] Presumably, "local installation" means putting packages in ~/.cabal/ . First question: where are global installs? I've been running cabal using sudo , so I guess that's a global install? The reason I've been doing this is that it

Proving “no corruption” in Haskell

无人久伴 提交于 2020-01-12 06:33:29
问题 I work in a safety-critical industry, and our software projects generally have safety requirements imposed; things that we have to demonstrate that the software does to a high degree of certainty. Often these are negatives, such as " shall not corrupt more frequently than 1 in ". (I should add that these requirements come from statistical system safety requirements). One source of corruption is clearly coding errors, and I would like to use the Haskell type system to exclude at least some

Always guaranteed evaluation order of `seq` (with strange behavior of `pseq` in addition)

余生颓废 提交于 2020-01-12 06:30:23
问题 The documentation of seq function says the following: A note on evaluation order: the expression seq a b does not guarantee that a will be evaluated before b . The only guarantee given by seq is that the both a and b will be evaluated before seq returns a value. In particular, this means that b may be evaluated before a . If you need to guarantee a specific order of evaluation, you must use the function pseq from the "parallel" package. So I have a lazy version of sum function with

Record syntax and sum types

狂风中的少年 提交于 2020-01-12 06:22:06
问题 I have this question about sum types in Haskell. I'd like to create a sum type which is comprised of two or more other types, and each of the types may contain multiple fields. A trivial example would be like this: data T3 = T1 { a :: Int, b :: Float} | T2 { x :: Char } deriving (Show) In my understanding, T1 and T2 are data constructors which use record syntax. It seems that the definition of T3 will grow as the number of fields in T1 or T2 increases. My question is that how to practically

reactive-banana time delays

帅比萌擦擦* 提交于 2020-01-12 05:27:06
问题 I have scoured the documentation of reactive-banana, and I can't find a way to specify explicit time delays. Say, for example, I would like to take an Event t a and shift all of its occurrences 1 second into the future; or get an event that fires 1 second from now (within Moment t ); or anything like that. Are explicit delays representable in reactive-banana? If not, how do users implement, e.g., echoing input delayed by a second? 回答1: As Ben indicates, this is correct: reactive-banana is no