ghc

How to combine case statement patterns [duplicate]

拈花ヽ惹草 提交于 2019-12-21 12:15:05
问题 This question already has answers here : Haskell syntax for 'or' in case expressions (5 answers) Closed 4 years ago . I'm trying to match on many different constructors in a case statement. For simplicity, assume in half the cases we do the same thing, and in the other half we do something else. Even if I factor out the logic to another function, I still have to write: case x of C1 -> foo x C2 -> foo x ... C10 -> bar x C11 -> bar x ... Is there some way to make case statements behave more

Warning on specialisations when compiling Haskell Code with ghc

女生的网名这么多〃 提交于 2019-12-21 11:28:29
问题 I get the following error when trying to compile $ ghc --make -O2 -Wall -fforce-recomp [1 of 1] Compiling Main ( isPrimeSmart.hs, isPrimeSmart.o ) SpecConstr Function `$wa{v s2we} [lid]' has two call patterns, but the limit is 1 Use -fspec-constr-count=n to set the bound Use -dppr-debug to see specialisations Linking isPrimeSmart ... My code is: {-# OPTIONS_GHC -O2 -optc-O2 #-} import qualified Data.ByteString.Lazy.Char8 as StrL -- StrL is STRing Library import Data.List -- read in a file.

How to customize Readline keybindings of GHCi?

江枫思渺然 提交于 2019-12-21 08:17:09
问题 I know GHCi supports Readline, and keybindings such as ^W and ^U work as expected. I do wonder whether ghci support customization of keybindings the way Bash deals with inputrc. 回答1: What is your GHC version? GHCi stopped using readline and started using libedit around 6.10 and haskeline around 6.12. libedit can be configured in ~/.editrc; similarly, Haskeline has ~/.haskeline. For example, I have # ~/.editrc (for libedit) edit on bind ^R em-inc-search-prev bind ^S em-inc-search-next bind ^[

'Failed to load interface' error when loading compiled modules in ghci

拈花ヽ惹草 提交于 2019-12-21 07:08:53
问题 Hello Haskell community, I'm new to Haskell and ran into a problem when I tried to structure my first bigger project. Here's the minimal example of the problem (I'm using cabal to build). This is the directory structure of a simple module: FooMod1 |- FooMod1.cabal |- Setup.hs |- src |- FooMod1.hs |- FooMod1 |- C1.hs |- T1.hs The source for FooMod1.hs: module FooMod1 ( C1(..) , T1(..) , ) where import FooMod1.C1 import FooMod1.T1 The source for C1.hs: module FooMod1.C1 ( C1(..) ) where class

How to upgrade GHC with Stack

时光怂恿深爱的人放手 提交于 2019-12-21 03:50:33
问题 The output of stack ghc -- --version is The Glorious Glasgow Haskell Compilation System, version 7.10.3 I want to upgrade to GHC 8. How can I tell Stack to upgrade GHC? 回答1: User dysfun from the IRC answered my question so I will post it here for posterity. To update GHC that's used to compile a project, go to the project's stack.yaml file. In there is the resolver field. Update that accordingly. Some examples: resolver: ghc-8.0.2 resolver: lts-9.0 resolver: nightly-2015-09-21 For my case, I

What is AllowAmbiguousTypes and why is it needed in this “forall” example?

↘锁芯ラ 提交于 2019-12-21 03:43:28
问题 The code {-# LANGUAGE ScopedTypeVariables, TypeApplications #-} -- I know this particular example is silly. -- But that's not the point here. g :: forall a . RealFloat a => Bool g = True main :: IO () main = print (g @Double) fails to compile on GHC 8.0 with the error • Could not deduce (RealFloat a0) from the context: RealFloat a bound by the type signature for: g :: RealFloat a => Bool at app/Main.hs:3:6-35 The type variable ‘a0’ is ambiguous • In the ambiguity check for ‘g’ To defer the

How to dump GHC simplifier output in human-readable form?

蓝咒 提交于 2019-12-21 03:33:27
问题 I have the following program: data Peano = Zero | Succ Peano deriving (Show) add Zero b = b add (Succ a) b = add a (Succ b) mul Zero b = Zero mul (Succ a) b = add b (mul a b) four x = let two = Succ (Succ Zero) in mul two two I want to get something like this from GHC: add = \ ds b -> case ds of Zero -> b Succ a -> add a (Succ b) mul = \ ds b -> case ds of Zero -> Zero Succ a -> add b (mul a b) four = let two = Succ (Succ Zero) in mul two two The best I managed to get is ghci -ddump-simpl

Multiple folds in one pass using generic tuple function

≡放荡痞女 提交于 2019-12-20 20:38:09
问题 How can I write a function which takes a tuple of functions of type ai -> b -> ai and returns a function which takes a tuple of elements of type ai , one element of type b , and combines each of the elements into a new tuple of ai : That is the signature should be like f :: (a1 -> b -> a1, a2 -> b -> a2, ... , an -> b -> an) -> (a1, a2, ... , an) -> b -> (a1, a2, ... , an) Such that: f (min, max, (+), (*)) (1,2,3,4) 5 = (1, 5, 8, 20) The point of this is so I can write: foldlMult' t = foldl'

A workaround for the “Template Haskell + C” bug?

一笑奈何 提交于 2019-12-20 20:23:14
问题 I've got the following situation: Library X is a wrapper over some code in C. Library A depends on library X. Library B uses Template Haskell and depends on library A. GHC bug #9010 makes it impossible to install library B using GHC 7.6. When TH is processed, GHCi fires up and tries to load library X, which fails with a message like Loading package charsetdetect-ae-1.0 ... linking ... ghc: ~/.cabal/lib/x86_64-linux-ghc-7.6.3/charsetdetect-ae-1.0/ libHScharsetdetect-ae-1.0.a: unknown symbol `

Dynamically loading compiled Haskell module - GHC 7.6

♀尐吖头ヾ 提交于 2019-12-20 18:29:49
问题 I'm trying to dynamically compile and load Haskell modules using GHC API. I understand the API fluctuates quite a bit from on one version to another so I'm specifically talking about GHC 7.6.*. I have tried running the same code on MacOS and Linux. In both cases the Plugin module compiles fine but gives the following error on load: Cannot add module Plugin to context: not interpreted The problem is similar to the one in this where the module would only load if it was compiled in the same run