ghc

Are newtypes faster than enumerations?

删除回忆录丶 提交于 2019-12-20 17:57:02
问题 According to this article, Enumerations don't count as single-constructor types as far as GHC is concerned, so they don't benefit from unpacking when used as strict constructor fields, or strict function arguments. This is a deficiency in GHC, but it can be worked around. And instead the use of newtypes is recommended. However, I cannot verify this with the following code: {-# LANGUAGE MagicHash,BangPatterns #-} {-# OPTIONS_GHC -O2 -funbox-strict-fields -rtsopts -fllvm -optlc --x86-asm-syntax

Are newtypes faster than enumerations?

痴心易碎 提交于 2019-12-20 17:55:57
问题 According to this article, Enumerations don't count as single-constructor types as far as GHC is concerned, so they don't benefit from unpacking when used as strict constructor fields, or strict function arguments. This is a deficiency in GHC, but it can be worked around. And instead the use of newtypes is recommended. However, I cannot verify this with the following code: {-# LANGUAGE MagicHash,BangPatterns #-} {-# OPTIONS_GHC -O2 -funbox-strict-fields -rtsopts -fllvm -optlc --x86-asm-syntax

Using standard haskell generics libraries for typed type-isomorphisms

耗尽温柔 提交于 2019-12-20 17:36:04
问题 There are several generics libraries with numerous overlapping modules in just the Haskell Platform alone ( syb , Data.Typeable , Data.Data , GHC.Generics ), but I'm having trouble with a very basic generic programming task. I want to be able to convert between types of the same shape, i.e. I want a polymorphic, typed conversion function between isomorphic types, essentially what is offered at the end of this paper(PDF) where indexed type families are mentioned. I'm not concerned with

How to prevent common sub-expression elimination (CSE) with GHC

可紊 提交于 2019-12-20 16:35:12
问题 Given the program: import Debug.Trace main = print $ trace "hit" 1 + trace "hit" 1 If I compile with ghc -O (7.0.1 or higher) I get the output: hit 2 i.e. GHC has used common sub-expression elimination (CSE) to rewrite my program as: main = print $ let x = trace "hit" 1 in x + x If I compile with -fno-cse then I see hit appearing twice. Is it possible to avoid CSE by modifying the program? Is there any sub-expression e for which I can guarantee e + e will not be CSE'd? I know about lazy, but

Distributing a Haskell program as C source

不打扰是莪最后的温柔 提交于 2019-12-20 16:17:52
问题 Say I have a Haskell program or library that I'd like to make accessible to non-Haskellers, potentially C programmers. Can I compile it to C using GHC and then distribute this as a C source? If this is possible, can someone provide a minimal example? (e.g., a Makefile) Is it possible to use GHC to automatically determine what compiler flags and headers and needed, and then perhaps bundle this into a single folder? Basically I'm interested in being able to write portions of programs in C and

Why does GHC think that this type variable is not injective?

独自空忆成欢 提交于 2019-12-20 10:31:10
问题 I have this piece of code: {-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies, KindSignatures, GADTs, FlexibleInstances, FlexibleContexts #-} class Monad m => Effect p e r m | p e m -> r where fin :: p e m -> e -> m r data ErrorEff :: * -> (* -> *) -> * where CatchError :: (e -> m a) -> ErrorEff ((e -> m a) -> m a) m instance Monad m => Effect ErrorEff ((e -> m a) -> m a) a m where fin (CatchError h) = \f -> f h This doesn't compile, with this type error in the last line: Could not

Compiling very large constants with GHC

試著忘記壹切 提交于 2019-12-20 10:24:49
问题 Today I asked GHC to compile an 8MB Haskell source file. GHC thought about it for about 6 minutes, swallowing almost 2GB of RAM, and then finally gave up with an out-of-memory error. [As an aside, I'm glad GHC had the good sense to abort rather than floor my whole PC.] Basically I've got a program that reads a text file, does some fancy parsing, builds a data structure and then uses show to dump this into a file. Rather than include the whole parser and the source data in my final application

Why does performGC fail to release all memory?

为君一笑 提交于 2019-12-20 09:53:40
问题 Given the program: import Language.Haskell.Exts.Annotated -- from haskell-src-exts import System.Mem import System.IO import Control.Exception main :: IO () main = do evaluate $ length $ show $ fromParseResult $ parseFileContents $ "data C = C {a :: F {- " ++ replicate 400000 'd' ++ " -} }" performGC performGC performGC Using GHC 7.0.3, when I run: $ ghc --make Temp.hs -rtsopts && Temp.exe +RTS -G1 -S Alloc Copied Live GC GC TOT TOT Page Flts bytes bytes bytes user elap user elap ... 29463264

Impact on style of GHC -Wall

感情迁移 提交于 2019-12-20 09:53:09
问题 It is considered good practice to enable GHC warnings with -Wall . However, I've found out that fixing those warnings has a negative effect for some types of code constructs. Example 1: Using the do-notation equivalent of f >> will generate a warning if I don't explicitly use the _ <- f form: Warning: A do-notation statement discarded a result of type Char. Suppress this warning by saying "_ <- f", or by using the flag -fno-warn-unused-do-bind I understand that I can forget to do something

Impact on style of GHC -Wall

独自空忆成欢 提交于 2019-12-20 09:50:59
问题 It is considered good practice to enable GHC warnings with -Wall . However, I've found out that fixing those warnings has a negative effect for some types of code constructs. Example 1: Using the do-notation equivalent of f >> will generate a warning if I don't explicitly use the _ <- f form: Warning: A do-notation statement discarded a result of type Char. Suppress this warning by saying "_ <- f", or by using the flag -fno-warn-unused-do-bind I understand that I can forget to do something