ghc

Detect infinite loops in a GHC program

泪湿孤枕 提交于 2021-02-10 06:10:59
问题 In this example, action is an infinite loop created by mistake. Is there a way to detect such loops in a GHC program? action bucket manager url = catch (action bucket manager url) (\(e :: HttpException) -> Logger.warn $ "Problems with " ++ url) 回答1: Short answer: no. It certainly isn't possible to notice every infinite loop one could write down; this is famously known as the halting problem and the formal proof that one cannot write a loop-detecting program is so famous that there's even a Dr

About 'pseq' in Haskell

社会主义新天地 提交于 2021-02-08 12:34:08
问题 Consider the following two statements: (a `par` b) `pseq` (a + b) and a `par` (b `pseq` (a + b)) Can someone explain how their behavior differ from each other? For the first one, if the main thread has done with computing b but the spark computing a hasn't finished, will the main thread proceed to compute a + b ? 回答1: par a b is semantically equivalent to b , but it gives the hint that it might be useful to start evaluating a early. On the otherhand pseq forces the evaluation of its first

Simple regular expression substitution crashes on Windows using regex-compat

匆匆过客 提交于 2021-02-08 03:44:26
问题 The following code crashes when using GHC on Windows. It works perfectly on Linux. Does this make any sense or is there a bug? module Main where import qualified Text.Regex as Re -- from regex-compat import Debug.Trace main :: IO () main = do putStr $ cleanWord "jan" putStr $ cleanWord "dec" putStr $ cleanWord "jun" -- crashes here cleanWord :: String -> String cleanWord word_ = let word = trace (show word_) word_ in let re = Re.mkRegexWithOpts "(jun|jul|aug|sep|oct|nov|dec)" True False in Re

How to put constraints on type variable of kind `Constraint`?

人走茶凉 提交于 2021-02-07 05:02:20
问题 I'm playing around with the ConstraintKinds extension of GHC. I have the following data type, which is just a box for things fulfilling some one parameter constraint c : data Some (c :: * -> Constraint) where Some :: forall a. c a => a -> Some c For example, I could construct a box with some kind of number (arguably not very useful). x :: Some Num x = Some (1 :: Int) Now, as long as c includes the constraint Show , I could provide an instance of Show (Some c) . instance ??? => Show (Some c)

Special runtime representation of [] type?

社会主义新天地 提交于 2021-02-06 10:42:09
问题 Consider the simple definition of a length-indexed vector: data Nat = Z | S Nat infixr 5 :> data Vec (n :: Nat) a where V0 :: Vec 'Z a (:>) :: a -> Vec n a -> Vec ('S n) a Naturally I would at some point need the following function: vec2list :: Vec n a -> [a] However, this function is really just a fancy identity. I believe that the runtime representations of these two types are the same, so vec2list :: Vec n a -> [a] vec2list = unsafeCoerce should work. Alas, it does not: >vec2list ('a' :>

Why can't I import Control.Monad.Writer while I have mtl-2.2.2 installed?

你。 提交于 2021-02-05 10:49:47
问题 I am trying to import Writer monad which is defined in mtl-2.2.2 package which I have installed as I checked with ghc-pkg list . When I tried to do import Control.Monad.Writer in ghci it is giving me an error. I don't understand why? Prelude> import Control.Monad.Writer <no location info>: error: Could not find module ‘Control.Monad.Writer’ Perhaps you meant Control.Monad.Fail (from base-4.11.1.0) Control.Monad.Fix (from base-4.11.1.0) Control.Monad.Zip (from base-4.11.1.0) 来源: https:/

Haskell : can only load one file at a time via :load

a 夏天 提交于 2021-02-04 13:19:04
问题 suppose I have two modules NecessaryModule1 & NecessaryModule2 (as outlined in the post Haskell : loading ALL files in current directory path. Then I have noticed in both WinGHCi and GHCi that if I do : > :load NecessaryModule1 [1 of 1] Compiling NecessaryModule1 ( NecessaryModule1.hs, interpreted ) Ok, modules loaded: NecessaryModule1. > addNumber1 2 3 5 > :load NecessaryModule2 [1 of 1] Compiling NecessaryModule2 ( NecessaryModule2.hs, interpreted ) Ok, modules loaded: NecessaryModule2. >

Cabal missing dependencies on foreign libraries when install glib under Windows

删除回忆录丶 提交于 2021-01-28 07:42:24
问题 I need glib for threadscope to work. But I am not able to install it using cabal. I tried cabal install glib but getting the following error. I even tried downloading the library and installing it locally but get the same error. I am using Cygwin on Windows. I ran Cygwin setup to make sure I have the missing libraries. I was able to find glib, gobject but not gthread. Gtk2HsSetup.hs:25:2: warning: #warning Setup.hs is guessing the version of Cabal. If compilation of Setup.hs fails use -DCABAL

Cabal missing dependencies on foreign libraries when install glib under Windows

北慕城南 提交于 2021-01-28 07:31:52
问题 I need glib for threadscope to work. But I am not able to install it using cabal. I tried cabal install glib but getting the following error. I even tried downloading the library and installing it locally but get the same error. I am using Cygwin on Windows. I ran Cygwin setup to make sure I have the missing libraries. I was able to find glib, gobject but not gthread. Gtk2HsSetup.hs:25:2: warning: #warning Setup.hs is guessing the version of Cabal. If compilation of Setup.hs fails use -DCABAL

Could not find module `Control.Monad.State` after updating mtl

流过昼夜 提交于 2021-01-27 20:18:11
问题 I wanted to use the Control.Monad.Except module, but it turned out I had an outdated mtl package (It caused an import error - I had an obsolete module Control.Monad.Error ). So I did sudo cabal install mtl And it installed the 2.2.2 version. However, now I had two versions installed, 2.1.2 and 2.2.2 which still caused an import error. I followed instructions here and did sudo ghc-pkg unregister --force mtl-2.1.2 to remove the old version. But now I get an error: Could not find module `Control