ghc

Using gcc instead of clang in ghci or ghc

我与影子孤独终老i 提交于 2019-11-30 09:37:26
On Mac OSX 10.9, the default c compiler bundled with Xcode is clang . I installed gcc-4.9 with homebrew . Now I have two different gcc s, one is clang , the other is gcc . The default is clang . I want to use gcc when compiling Haskell files with ghc , and I want also gcc when I launch ghci . How to do this change? Carter Tazio Schonwald Reproducing my directions I've been sharing with haskellers for the past few months via https://gist.github.com/cartazio/7131371 Type ghc --print-libdir The output will be a path like /Library/Frameworks/GHC.framework/Versions/7.6.3-x86_64/usr/lib/ghc-7.6.3 Go

Is there any hope to cast ForeignPtr to ByteArray# (for a function :: ByteString -> Vector)

≯℡__Kan透↙ 提交于 2019-11-30 09:00:28
For performance reasons I would like a zero-copy cast of ByteString (strict, for now) to a Vector . Since Vector is just a ByteArray# under the hood, and ByteString is a ForeignPtr this might look something like: caseBStoVector :: ByteString -> Vector a caseBStoVector (BS fptr off len) = withForeignPtr fptr $ \ptr -> do let ptr' = plusPtr ptr off p = alignPtr ptr' (alignment (undefined :: a)) barr = ptrToByteArray# p len -- I want this function, or something similar barr' = ByteArray barr alignI = minusPtr p ptr size = (len-alignI) `div` sizeOf (undefined :: a) return (Vector 0 size barr')

Has anyone successfully built a Cygwin version of GHC?

不羁的心 提交于 2019-11-30 08:55:08
Has anyone successfully built a Cygwin version of GHC (since Haskell switched from using Cygwin to MinGW)? From the haskell website: "GHC targets MinGW, not Cygwin. It is in principle possible to build a version of GHC, GHC-cygwin, that targets Cygwin instead. The up-side of GHC-cygwin is that Haskell programs compiled by GHC-cygwin can import the (Haskell) Posix library. We do not support GHC-cygwin, however; it is beyond our resources." https://ghc.haskell.org/trac/ghc/wiki/Building/Platforms/Windows I tried, unsuccessfully, building with Cygwin's configure/gcc. This fails because I couldn't

Why does a more general type affect runtime in Haskell?

本小妞迷上赌 提交于 2019-11-30 08:20:13
Consider the two following implementations of an infinite Fibonacci sequence: fibsA :: Num a => [a] fibsA = 0:1:(zipWith (+) fibsA (tail fibsA)) fibsB :: [Integer] fibsB = 0:1:(zipWith (+) fibsB (tail fibsB)) In GHCI, executing fibsB !! k is much faster than executing fibsA !! k . In particular, it seems that the values of fibsA are continuously recalculated (not memoized/stored). Furthermore, when the type signature is omitted, GHCI's :t shows it to be [Integer] , and the function performs accordingly. This behavior also occurs in compiled code ( ghc -O3 Fibs.hs ). Why is it the case that

Need a tutorial for using GHC to parse and typecheck Haskell

。_饼干妹妹 提交于 2019-11-30 08:01:53
I'm working on a project for analyzing Haskell code. I decided to use GHC to parse the source and infer types rather than write my own code to do that. Right now, I'm slogging through the Haddock docs, but it's slow going. Does anyone know of a good tutorial? EDIT: To clarify, I'm not looking for something like hlint. I'm writing my own tool to analyze the runtime characteristics of Haskell code, so it's like I'm writing a different hlint. What I'm looking for is basically an expansion of the wiki page GHC As a library . Adam, this is pretty tough sledding. Ever since its launch in 2006, the

Uncurry for n-ary functions

风流意气都作罢 提交于 2019-11-30 05:47:20
问题 I have a type level numbers data Z deriving Typeable data S n deriving Typeable and n-ary functions (code from fixed-vector package) -- | Type family for n-ary functions. type family Fn n a b type instance Fn Z a b = b type instance Fn (S n) a b = a -> Fn n a b -- | Newtype wrapper which is used to make 'Fn' injective. It's also a -- reader monad. newtype Fun n a b = Fun { unFun :: Fn n a b } I need function like uncurryN :: Fun (n + k) a b -> Fun n a (Fun k a b) I read several articles about

How to relate to type from outer context

狂风中的少年 提交于 2019-11-30 04:16:29
Let us consider the following code snippet: blah :: a -> b -> a blah x y = ble x where ble :: b -> b ble x = x This compiles fine under GHC, which essentially means that b from the 3rd line is something different than b from the first line. My question is simple: is there a way to somehow relate in the type declaration of ble to a type used in an outer context, i.e. the type declaration of blah ? Obviously, this is just an example and not a real-world use-case for type declarations. This is possible with the ScopedTypeVariables extension. You need to use explicit forall's to bring the type

How can I load optimized code in GHCI?

本秂侑毒 提交于 2019-11-30 04:13:44
I am writing a module that relies on optimization. I want to test this module in ghci. But starting ghc in --interactive mode automatically disables optimization; if I compile the module with -O and then try to load it in an interactive session, ghc insists on loading it in interpreted mode. For a simple test case to distinguish optimized and unoptimized modules, isOptimized below evaluates to True with optimization on, but False with optimization off: isOptimized :: Bool isOptimized = g g :: Bool g = False {-# NOINLINE g #-} {-# RULES "g/True" g = True #-} Either use ghci -fobject-code -O

Haskell and memoization of pure function results [duplicate]

瘦欲@ 提交于 2019-11-30 04:04:40
Possible Duplicate: When is memoization automatic in GHC Haskell? As a consequence, pure function always returns the same value for a fixed input. That said, does Haskell (more precisely GHC) automatically cache (memoize) these results if there is enough memory (question 1) and does developer have any control on it (question 2)? Philip JF I voted to close, but short answer: GHC does not do any automatic memoization of functions, and that is probably a good thing because it would make space complexity even harder to reason about. Also, memoization is not in general a very solvable problem,

Haskell Error: parse error on input `='

﹥>﹥吖頭↗ 提交于 2019-11-30 03:56:57
问题 Specs GHC 6.12.1 Mac OS X 10.6.4 x64 MacBook Pro Problem I'm having trouble using let syntax. The following code refuses to compile: module Main where main = let x = 1 y = 2 z = 3 in putStrLn $ "X = " ++ show x ++ "\nY = " ++ show y ++ "\nZ = " ++ show z I tried tabbing in y = 2 and z = 3 even more. No dice. (Undesirable) Solutions The only way I've gotten the code to compile is either Replacing hard tabs with spaces. Replacing the let clause with a where clause. 回答1: Saizan on #haskell