haskell

Error with cabal update

流过昼夜 提交于 2020-01-05 12:34:23
问题 On a fresh install install of Haskell-Platform (64 bit OSX version from http://www.haskell.org/platform/mac.html) I get the following error: Downloading the latest package list from hackage.haskell.org Warning: http error: Network.Browser.request: Error raised ErrorParse "Invalid cabal: Char.intToDigit: not a digit -1 After issuing the command cabal update . No luck with any searches and I have no idea where this error is coming from. 回答1: I had the same problem. The only workaround I could

Error with cabal update

孤人 提交于 2020-01-05 12:33:54
问题 On a fresh install install of Haskell-Platform (64 bit OSX version from http://www.haskell.org/platform/mac.html) I get the following error: Downloading the latest package list from hackage.haskell.org Warning: http error: Network.Browser.request: Error raised ErrorParse "Invalid cabal: Char.intToDigit: not a digit -1 After issuing the command cabal update . No luck with any searches and I have no idea where this error is coming from. 回答1: I had the same problem. The only workaround I could

Why can't I redefine the : operator in Haskell?

混江龙づ霸主 提交于 2020-01-05 11:56:13
问题 I'm trying to reimplement some functionality of the list data type in Haskell for learning purposes. When I try to redefine : with this code: {-# LANGUAGE NoImplicitPrelude #-} data List a = Nil | Cons a (List a) (:) :: a -> List a -> List a (:) = Cons I get the following error with stack runghc : Invalid type signature: (:) :: ... Should be of form <variable> :: <type> Is it impossible to redefine : ? Is that why I'm getting this error? 回答1: It is impossible to redefine : , but that is not

Encapsulating data definitions in Haskell

和自甴很熟 提交于 2020-01-05 09:19:11
问题 I am trying to define a data type using other data types like this: data A = Something String | SomethingElse Int data B = Another B | YetAnother A data C = A | B x :: [ C ] x = [ YetAnother (SomethingElse 0), Something "Hello World" ] But this is giving me an error saying that I cannot have a type A when expecting a type B. Why is this? 回答1: You're missing the data constructors for C . data A = Something String | SomethingElse Int data B = Another B | YetAnother A data C = C0 A | C1 B x :: [

Extensible records (I think)

懵懂的女人 提交于 2020-01-05 08:45:52
问题 What I roughly want is this: data A = ... data B = ... data C = ... class HasA t where getA :: t -> A class HasB t where getB :: t -> B class HasC t where getC :: t -> C So I can do something like this (pseudocode follows): a :: A b :: B x = mkRecord { elemA a, elemB b } y = mkRecord { elemB b, elemA a } -- type of `x` == type of `y` Naturally, only the appropriate get functions work, in the above case getA and getB . I'd also like the following functions slice :: Subset a b => a -> b slice x

How to be certain that all threads have been killed upon pressing Ctrl+C

淺唱寂寞╮ 提交于 2020-01-05 07:10:30
问题 I'm running a servant server and another background thread (via async ) in gchi . When I press Ctrl+c on the GHCi prompt, the servant server shuts down properly, but my background thread keeps running. Only quitting the entire GHCi session seems to really terminate it. Two questions: Is this behaviour only because I'm in GHCi? If I compiled a binary, ran it, and then pressed Ctrl+C on it, would the background-thread still keep running? How do I solve for this properly? 回答1: Is this behaviour

How to be certain that all threads have been killed upon pressing Ctrl+C

时光总嘲笑我的痴心妄想 提交于 2020-01-05 07:09:18
问题 I'm running a servant server and another background thread (via async ) in gchi . When I press Ctrl+c on the GHCi prompt, the servant server shuts down properly, but my background thread keeps running. Only quitting the entire GHCi session seems to really terminate it. Two questions: Is this behaviour only because I'm in GHCi? If I compiled a binary, ran it, and then pressed Ctrl+C on it, would the background-thread still keep running? How do I solve for this properly? 回答1: Is this behaviour

Split a string by a chosen character in haskell

给你一囗甜甜゛ 提交于 2020-01-05 06:42:13
问题 I'm trying to split a string every time there is a chosen character. So if I receive "1,2,3,4,5" , and my chosen character is "," the result is a list such as ["1","2","3","4","5"] . I've been looking through the already answered questions in here and they point me to using splitOn . However, when i try to import Data.List.Split in order to use it, Haskell gives me the following error: Could not find module ‘Data.List.Split’ . When I tried to just use splitOn without importing the module, it

Programmatically Listing `C-sources` in Haskell Cabal Files

社会主义新天地 提交于 2020-01-05 05:44:06
问题 I am involved in a Haskell project which involves a lot of C FFI. Thus, for every src/HaskellFile.hs I have in my project, I have a corresponding src/HaskellFile.c C source file. This means I have to manually this all of these C sources in my cabal project: C-sources: src/HaskellFile1.c, src/HaskellFile2.c ...and so forth. Question: Is it possible to programmatically list out these files in my cabal project file? Something like: C-sources: src/*.c ..? (For the record, I tried the above and it

Generate all permutations of a list including diferent sizes and repeated elements

戏子无情 提交于 2020-01-05 05:10:20
问题 I wanted to create the function genAllSize ::[a] -> [[a]] , that receives a list l and generates all the lists sorted by size that can be built with the elements of the list l ; i.e. > genAllSize [2,4,8] [[],[2],[4],[8],[2,2],[4,2],[8,2],[2,4],[4,4],[8,4],[2,8],[4,8],[8,8],[2,2,2],[4,2,2],[8,2,2], ... How would you do it? I came up with a solution using permutations from Data.List but I do not want to use it. 回答1: Given an input list xs , select a prefix of that in a non deterministic way For