ghc

What optimizations can GHC be expected to perform reliably?

╄→尐↘猪︶ㄣ 提交于 2019-11-29 18:35:49
GHC has a lot of optimizations that it can perform, but I don't know what they all are, nor how likely they are to be performed and under what circumstances. My question is: what transformations can I expect it to apply every time, or nearly so? If I look at a piece of code that's going to be executed (evaluated) frequently and my first thought is "hmm, maybe I should optimize that", in which cases should my second thought be, "don't even think about it, GHC got this"? I was reading the paper Stream Fusion: From Lists to Streams to Nothing at All , and the technique they used of rewriting list

Haskell : display/get list of all user defined functions

独自空忆成欢 提交于 2019-11-29 17:14:14
问题 Is there a command in Haskell which displays (or get as a list of) all the user defined functions which have been loaded/defined in the GHCi? Thanks 回答1: To see bindings you've made at the ghci prompt (e.g. with let or <- ), try :show bindings . If you've loaded some modules, you can use :show modules to get the names of loaded modules and then :browse ModuleName to list everything in scope from that module. 回答2: When in ghci, use :browse or just :bro after loading the file. You may also

How to define function only for old versions in GHC?

本小妞迷上赌 提交于 2019-11-29 15:45:01
I have a code that uses the fromRight function defined circa GHC 8.2. But I need to downgrade to GHC 8.0.2, which gives an error about Variable not in scope: for fromRight I was wondering if it possible and how to add the missing definition fromRight :: b -> Either a b -> b fromRight _ (Right b) = b fromRight b _ = b so that it is only used when I use an GHC version than 8.2.1? You can always write import Prelude hiding (fromRight) which is valid even if fromRight does not exist in Prelude. Therefore, if you want to write a module which is compatible with both old and new versions of Prelude,

Using gcc instead of clang in ghci or ghc

核能气质少年 提交于 2019-11-29 14:25:06
问题 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? 回答1: 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

what is the meaning of “let x = x in x” and “data Float#” in GHC.Prim in Haskell

≯℡__Kan透↙ 提交于 2019-11-29 13:10:19
I looked at the module of GHC.Prim and found that it seems that all datas in GHC.Prim are defined as data Float# without something like =A|B , and all functions in GHC.Prim is defined as gtFloat# = let x = x in x . My question is whether these definations make sense and what they mean. I checked the header of GHC.Prim like below {- This is a generated file (generated by genprimopcode). It is not code to actually be used. Its only purpose is to be consumed by haddock. -} I guess it may have some relations with the questions and who could please explain that to me. It's magic :) These are the

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

倖福魔咒の 提交于 2019-11-29 13:03:08
问题 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

Has anyone successfully built a Cygwin version of GHC?

独自空忆成欢 提交于 2019-11-29 12:35:16
问题 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

Why does a more general type affect runtime in Haskell?

回眸只為那壹抹淺笑 提交于 2019-11-29 11:27:54
问题 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

Need a tutorial for using GHC to parse and typecheck Haskell

∥☆過路亽.° 提交于 2019-11-29 11:24:56
问题 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

Understanding this definition of HList

感情迁移 提交于 2019-11-29 11:08:19
I'm relatively new to Haskell, and I'm trying to understand one of the definitions of HList . data instance HList '[] = HNil newtype instance HList (x ': xs) = HCons1 (x, HList xs) pattern HCons x xs = HCons1 (x, xs) I have a couple specific questions: What is the '[] and (x ': xs) syntax I'm seeing? It almost looks like it's pattern matching on variadic type parameters, but I have never seen this syntax before, nor am I familiar with variadic type parameters in Haskell. I would guess this is part of GHC's Type Families , but I don't see anything about this on the linked page, and it's rather