ghc

Why doesn't stack add packages to the ghc package database?

喜欢而已 提交于 2019-12-22 05:34:14
问题 I've decided to try giving stack a shot. I've installed it and used it to install the latest version of ghc. I've used stack to install some packages but the packages are not visible to ghc and when I list packages with ghc-pkg I see that the packages that I've installed through stack are not there. Why is this? Am I misunderstanding the purpose of stack? 回答1: Stack never touches global packages database. It uses layered database approach global database - untouched packages in the stackage

Is there a way to only compile Haskell source to interface file, not further? [duplicate]

随声附和 提交于 2019-12-22 05:31:53
问题 This question already has answers here : Haskell: How to only generate .hi file with ghc? (2 answers) Closed last year . Usually, when ghc is compiling a source code, it will produce at least an .o (object) and a .hi (interface) file. In the interest of diminishing compilation time, if I only need an interface file, can I somehow order ghc to abandon everything else and just give me said interface file? Or, otherwise, obtain that interface by any kind of lowly guile? I found this ghc user

How to force GHC to inline FFI calls?

天大地大妈咪最大 提交于 2019-12-22 05:26:11
问题 I made small C module to improve performance, but GHC doesn't inline foreign functions, and calls cost eliminates the acceleration. For example, test.h : int inc (int x); test.c : #include "test.h" int inc(int x) {return x + 1;} Test.hc : {-# LANGUAGE ForeignFunctionInterface #-} module Test (inc) where import Foreign import Foreign.C foreign import ccall unsafe "test.h inc" c_inc :: CInt -> CInt inc = fromIntegral . c_inc . fromIntegral {-# INLINE c_inc #-} {-# INLINE inc #-} Main.hs :

Type Inference in Patterns

谁都会走 提交于 2019-12-22 05:23:14
问题 I noticed that GHC wanted a type signature which I think should be inferred. I minimized my example down to this, which almost certainly does nothing meaningful (I don't recommend running it on your favorite types): {-# LANGUAGE GADTs, RankNTypes, ScopedTypeVariables, TypeOperators, NoMonomorphismRestriction #-} module Foo where import Data.Typeable data Bar rp rq data Foo b = Foo (Foo b) rebar :: forall rp rq rp' rp'' . (Typeable rp', Typeable rp'') => Proxy rp' -> Proxy rp'' -> Foo rp ->

Haskell GHC Dynamic Compliation Only works on first compile

柔情痞子 提交于 2019-12-22 04:58:20
问题 Following the GHC tutorial posted here and alterations to this code following the advice in a previous stack overflow question I asked, I have created a program which is able to compile and run a module in Test.hs with a function print to print a string to the screen: import GHC import GHC.Paths import DynFlags import Unsafe.Coerce main :: IO () main = defaultErrorHandler defaultLogAction $ do func <- runGhc (Just libdir) $ do dflags <- getSessionDynFlags setSessionDynFlags dflags target <-

Can GHC derive Functor and Applicative instances for a monad transformer?

淺唱寂寞╮ 提交于 2019-12-22 04:42:31
问题 I'm trying to implement MaybeT in the spirit of the mtl library. With this non-compiling solution: {-# LANGUAGE FlexibleInstances, MultiParamTypeClasses, UndecidableInstances #-} import Control.Monad import Control.Monad.Trans import Control.Monad.State newtype MaybeT m a = MaybeT { runMaybeT :: m (Maybe a) } instance (Monad m) => Monad (MaybeT m) where x >>= f = MaybeT $ runMaybeT x >>= maybe (return Nothing) (runMaybeT . f) return a = MaybeT $ return (Just a) fail _ = MaybeT $ return

RankNTypes: What is causing this error?

允我心安 提交于 2019-12-22 03:57:01
问题 I've just been exploring Rank2Types and RankNTypes to try to get familiar with them. But I can't work out why the following does not work. g :: (forall a. forall b. a -> b) -> x -> y -> (u,v) g p x y = (p x, p y) This definition is accepted by the compiler, but it fails when I try to use it: ghci> g id 1 2 <interactive>:35:3: Couldn't match type `a' with `b' `a' is a rigid type variable bound by a type expected by the context: a -> b at <interactive>:35:1 `b' is a rigid type variable bound by

Optimization of Function Calls in Haskell

醉酒当歌 提交于 2019-12-22 02:52:30
问题 Not sure what exactly to google for this question, so I'll post it directly to SO: Variables in Haskell are immutable Pure functions should result in same values for same arguments From these two points it's possible to deduce that if you call somePureFunc somevar1 somevar2 in your code twice, it only makes sense to compute the value during the first call. The resulting value can be stored in some sort of a giant hash table (or something like that) and looked up during subsequent calls to the

Adding context to rewrite rules

那年仲夏 提交于 2019-12-21 20:44:59
问题 In the following code, I want to rewrite g . f as h when possible. There may be cases h hasn't got the instance of class, but I'd like to do the rewrite when it's possible. I'm getting an error message suggesting this is achievable but I'm not sure exactly what I need to change. Here is some sample code: {-# LANGUAGE TypeFamilies #-} main = return () data D a f :: a -> D a f = undefined type family T a class G a where g :: D (T a) -> a class H a where h :: T a -> a {-# RULES "myrule" forall x

Searching for rewrite rules

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-21 16:22:29
问题 Is there any way to browse or search rewrite rules? When I use flags like -ddump-rule-firings or -ddump-rule-rewrites I just get the name of the rule that fired and the rewrite that it caused, but not the actual rule itself... Ideally I'd like to see what rewrite rules are in scope via GHCi, but realistically I'd be willing to settle for just an exhaustive list of the rewrite rules present in base. 回答1: Alright, still hoping for a good answer to this, but if there isn't, I went ahead and did