haskell

cabal dependency resolution fail for 'lens'

允我心安 提交于 2020-01-14 10:06:36
问题 I just did a cabal update and tried to install 'lens' from hackage. That gave me the following error - $ cabal install -j lens Resolving dependencies... Configuring dlist-0.7.0.1... ... <snip> Configuring mtl-2.0.1.0... Building mtl-2.0.1.0... Failed to install mtl-2.0.1.0 Last 10 lines of the build log ( /home/aj/.cabal/logs/mtl-2.0.1.0.log ): Building mtl-2.0.1.0... Preprocessing library mtl-2.0.1.0... [ 1 of 21] Compiling Control.Monad.Writer.Class ( Control/Monad/Writer/Class.hs, dist

How much should one control the `Depth` parameter in smallcheck?

无人久伴 提交于 2020-01-14 09:38:27
问题 I'm doing my first bit of real work with smallcheck , and I'm a little confused about how to use the Depth parameter. Before I go into that, let me state what I'm using smallcheck for. At work, we're building a simple web service in front of our own in-house database. The web service does some queries, and responds with the query results serialized to JSON. What I'm working on at the moment is the assurance that: given an object that represents the results of a query, this object produces the

How does GHCi print partially-applied values created from “pure”?

ⅰ亾dé卋堺 提交于 2020-01-14 09:32:21
问题 I've been playing around with Applicative instances in order to figure out how they work. However, I honestly don't understand this behavior. If I define my own datatype, then apply pure to it with no other arguments, nothing prints out, but it errors if I try to apply something to the result. ghci> data T = A ghci> pure A ghci> pure A 0 <interactive>:21:1: No instance for (Show T) arising from a use of ‘print’ In a stmt of an interactive GHCi command: print it However, if I make T an

How does GHCi print partially-applied values created from “pure”?

不打扰是莪最后的温柔 提交于 2020-01-14 09:32:08
问题 I've been playing around with Applicative instances in order to figure out how they work. However, I honestly don't understand this behavior. If I define my own datatype, then apply pure to it with no other arguments, nothing prints out, but it errors if I try to apply something to the result. ghci> data T = A ghci> pure A ghci> pure A 0 <interactive>:21:1: No instance for (Show T) arising from a use of ‘print’ In a stmt of an interactive GHCi command: print it However, if I make T an

Real World Haskell Chapter 3 excercise: Binary Tree with 1 value constructor

这一生的挚爱 提交于 2020-01-14 07:51:09
问题 Chapter 3 defines the following recursive type to represent a binary tree: data Tree a = Node a (Tree a) (Tree a) | Empty deriving (Show) The exercise requires I implement the same type using a single value constructor, using the "Maybe" type to refer to child nodes: (From Chapter 3 Exercise 2 on page 60) "Define a tree type that has only one constructor, like our Java example. Instead of the Empty constructor, use the Maybe type to refer to a node's children." The solution I came up with is

Why does `changes` return `Event t (Future a)`

邮差的信 提交于 2020-01-14 07:33:25
问题 The changes function has type Frameworks t => Behavior t a -> Moment t (Event t (Future a)) . Future is abstract and there is only one function that consumes it ( reactimate' ). However, I can easily write the following function: changes' :: Frameworks t => Behavior t a -> Moment t (Event t a) changes' b = fmap (fmap const b <@>) (changes b) to get a normal (non- Future ) event. Is something wrong with that function? If not, why does the original changes function have a more restrictive type?

Implicit parameter and function

谁说胖子不能爱 提交于 2020-01-14 07:27:47
问题 I have a problem considering implicit parameters in Haskell (GHC). I have a function f , that assumes the implicit parameter x , and would like to encapsulate it in a context by applying f to g f :: (?x :: Int) => Int -> Int f n = n + ?x g :: (Int -> Int) -> (Int -> Int) g t = let ?x = 5 in t But when i try to evaluate g f 10 I get an error that x is not bound, e.g.: Unbound implicit parameter (?x::Int) arising from a use of `f' In the first argument of `g', namely `f' In the second argument

What does “⊥” mean in “The Strictness Monad” from P. Wadler's paper?

一世执手 提交于 2020-01-14 07:21:08
问题 Can someone help me understand the following definition from Wadler's paper titled "Comprehending Monads"? (Excerpt is from section 3.2/page 9, i.e., the "Strictness Monad" subsection.) Sometimes it is necessary to control order of evaluation in a lazy functional program. This is usually achieved with the computable function strict , defined by strict f x = if x ≠ ⊥ then f x else ⊥. Operationally, strict f x is reduced by first reducing x to weak head normal form (WHNF) and then reducing the

Why does let y = 1 + y compile, and what does it mean?

≯℡__Kan透↙ 提交于 2020-01-14 07:08:31
问题 In GHCi let y = y + 1 compiles fine, but when I try to evaluate y I got *** Exception: <<loop>> Why is there no compile error and what does it mean <<loop>> ? 回答1: Haskell let , where and top-level bindings are recursive by default , even if they're not for a function. So let y = y + 1 defines an infinite loop of adding 1 to a number. GHC represents loops like this with the <<loop>> exception—if it can catch them, of course! This is usable for lazy operations, because it allows us to easily

Is this a safe use of unsafeCoerce?

二次信任 提交于 2020-01-14 07:04:52
问题 I have a situation where I am at the moment using the extremely scary function unsafeCoerce. It's not for anything important fortunately, but I was wondering whether this seems to be a safe usage of this function, or whether there would be another way to solve this particular problem that other people know of. The code I have is something like the following: data Token b = Token !Integer identical :: Token a -> Token b -> Bool identical (Token a) (Token b) = a == b data F a = forall b. F