haskell

Resolving Network.HTTP 'user error (https not supported)'

北城余情 提交于 2021-02-09 02:40:14
问题 When running this Haskell program using runghc : import Network.HTTP main = simpleHTTP (getRequest "https://stackoverflow.com") >>= getResponseBody >>= putStrLn I get the error message printso.hs: user error (https not supported) I don't want to switch to unencrypted HTTP -- how can I use Network.HTTP with SSL/TLS? 回答1: You can't do that directly, see for example this post. However you could use Network.HTTP.Conduit from the http-conduit library instead. First install it using cabal install

Resolving Network.HTTP 'user error (https not supported)'

萝らか妹 提交于 2021-02-09 02:37:31
问题 When running this Haskell program using runghc : import Network.HTTP main = simpleHTTP (getRequest "https://stackoverflow.com") >>= getResponseBody >>= putStrLn I get the error message printso.hs: user error (https not supported) I don't want to switch to unencrypted HTTP -- how can I use Network.HTTP with SSL/TLS? 回答1: You can't do that directly, see for example this post. However you could use Network.HTTP.Conduit from the http-conduit library instead. First install it using cabal install

Why does this instance fail the coverage condition?

99封情书 提交于 2021-02-08 23:45:00
问题 Why does the following instance declaration fail the coverage condition in the absence of UndecidableInstances ? It seems that if the functional dependency is satisfied in the context then it is satisfied in the new instance. {-# LANGUAGE FunctionalDependencies #-} {-# LANGUAGE UndecidableInstances #-} class Foo a b | a -> b where instance (Foo a b, Foo a' b') => Foo (a, a') (b, b') where If I try to replicate the same thing with a type family there is no problem. {-# LANGUAGE TypeFamilies #-

typeclasses without methods, used as constraints: do they get dictionaries?

爱⌒轻易说出口 提交于 2021-02-08 20:50:14
问题 If I'm using a typeclass to overload methods, that's implemented in 'dictionary passing style'. That is, the method gets an extra argument (that doesn't appear in surface Haskell); to resolve overloading the method looks up the dictionary by type of its 'proper' argument(s); and pulls a method implementation out of the dictionary. As described in this q, for example. But what about typeclasses without methods? They can be used as constraints. Is there a dictionary for them? What does it

stack --nix build complains about ghc version mismatch

做~自己de王妃 提交于 2021-02-08 18:33:59
问题 When building threepenny-gui on NixOS with stack --nix build , I got error saying I have the wrong version of ghc. Then I tried stack --nix setup , which doesn't run because bash is on an unexpected path on NixOS (that's expected, since the stack documentation only mentions stack --nix build not setup ). What am I missing? FYI, to deal with the zlib issues I have also added a shell.nix and default.nix per https://github.com/commercialhaskell/stack/issues/2130 EDIT: was able to build with the

stack --nix build complains about ghc version mismatch

↘锁芯ラ 提交于 2021-02-08 18:30:27
问题 When building threepenny-gui on NixOS with stack --nix build , I got error saying I have the wrong version of ghc. Then I tried stack --nix setup , which doesn't run because bash is on an unexpected path on NixOS (that's expected, since the stack documentation only mentions stack --nix build not setup ). What am I missing? FYI, to deal with the zlib issues I have also added a shell.nix and default.nix per https://github.com/commercialhaskell/stack/issues/2130 EDIT: was able to build with the

stack --nix build complains about ghc version mismatch

时间秒杀一切 提交于 2021-02-08 18:29:55
问题 When building threepenny-gui on NixOS with stack --nix build , I got error saying I have the wrong version of ghc. Then I tried stack --nix setup , which doesn't run because bash is on an unexpected path on NixOS (that's expected, since the stack documentation only mentions stack --nix build not setup ). What am I missing? FYI, to deal with the zlib issues I have also added a shell.nix and default.nix per https://github.com/commercialhaskell/stack/issues/2130 EDIT: was able to build with the

How to change Ord instance for tuple of type (String, Int) without declaring a new data?

别等时光非礼了梦想. 提交于 2021-02-08 15:47:30
问题 I'm trying to sort a list of type [(String, Int)] . By default, it is sorting by Strings and then Ints (if the Strings are equal). I want it to be the opposite — first, compare Ints and then if equal compare the Strings. Additionally, I don't want to switch to [(Int, String)] . I found a way to do so by defining an instance, but it only works for my own data type, which I don't want to use. 回答1: You can sort with sortBy :: (a -> a -> Ordering) -> [a] -> [a]: import Data.List(sortBy) import

Local maxima of list using fold

耗尽温柔 提交于 2021-02-08 14:42:16
问题 Is there any way to find out local maxima of a list using foldr or foldl or maybe I have to use unfoldr because of first and last elements of list aren't local maximums? I understand how to find it using recursion with guards, e.g. localMax :: [Int] -> [Int] localMax [] = [] localMax (x:[]) = [] localMax (x:y:[]) = [] localMax (x:y:z:zs) | y > z && y > x = y:localMax (y:z:zs) | otherwise = localMax (y:z:zs) 回答1: I'll try to only use the fold, as you asked. What about something like this? lmax

Can't understand result of Monad >> application

那年仲夏 提交于 2021-02-08 14:12:13
问题 Operation >> description is the following: Sequentially compose two actions, discarding any value produced by the first, like sequencing operators (such as the semicolon) in imperative languages. Here is the example which confuses me: > ([1] ++ [2]) >> ([2] ++ [3]) [2,3,2,3] I'm expecting the list [2,3] which would be result of right part of expression. How can result of [2,3,2,3] be explained? 回答1: (>>) is by default defined as a >> b = a >>= (\_ -> b) so the value being ignored is an a in a