ghc

When is -XAllowAmbiguousTypes appropriate?

陌路散爱 提交于 2019-11-27 00:04:33
问题 I've recently posted a question about syntactic-2.0 regarding the definition of share . I've had this working in GHC 7.6 : {-# LANGUAGE GADTs, TypeOperators, FlexibleContexts #-} import Data.Syntactic import Data.Syntactic.Sugar.BindingT data Let a where Let :: Let (a :-> (a -> b) :-> Full b) share :: (Let :<: sup, sup ~ Domain b, sup ~ Domain a, Syntactic a, Syntactic b, Syntactic (a -> b), SyntacticN (a -> (a -> b) -> b) fi) => a -> (a -> b) -> b share = sugarSym Let However, GHC 7.8 wants

Are Functor instances unique?

老子叫甜甜 提交于 2019-11-26 23:03:25
问题 I was wondering to what extent Functor instances in Haskell are determined (uniquely) by the functor laws. Since ghc can derive Functor instances for at least "run-of-the-mill" data types, it seems that they must be unique at least in a wide variety of cases. For convenience, the Functor definition and functor laws are: class Functor f where fmap :: (a -> b) -> f a -> f b fmap id = id fmap (g . h) = (fmap g) . (fmap h) Questions: Can one derive the definition of map starting from the

Why does this function that uses a scoped type variable in a where clause not typecheck?

不羁的心 提交于 2019-11-26 21:50:02
问题 I have a function that has a value defined in a where clause, and I want to give it an explicit type annotation. The annotation needs to use a type variable from the top-level function, so it was my understanding that I needed to use ScopedTypeVariables . Here is a minimal reduction of the problem: {-# LANGUAGE ScopedTypeVariables #-} import Control.Monad.Trans.Except import Data.Functor.Identity f :: ExceptT String Identity a -> Maybe a f m = Nothing where x :: Identity (Either String a) x =

No instance for (Floating Int)

老子叫甜甜 提交于 2019-11-26 21:49:36
问题 I am learning Haskell. I have created function which returns multiplication table up to 'n' in base 'b'. Numbers are padded to 'w' digits. As the last step, I want to compute 'w' automatically. Why does this not compile? -- Number of digits needed for the multiplication table n*n in base 'base' nOfDg :: Int -> Int-> Int nOfDg n base = 1 + floor ( logBase base (n*n)) error: No instance for (Floating Int) arising from a use of `logBase' at C:\haskel\dgnum.hs:4:24-38 Possible fix: add an

Statically link GMP to an Haskell application using GHC (+ LLVM)

前提是你 提交于 2019-11-26 20:14:15
问题 How can I drop dynamic dependency on libgmp and go from this: linux-vdso.so.1 => (0x00007fffdccb1000) libgmp.so.10 => /usr/lib/x86_64-linux-gnu/libgmp.so.10 (0x00007fb01afc1000) libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fb01acc7000) librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fb01aabe000) libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fb01a8ba000) libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fb01a69d000) libc.so.6 => /lib/x86_64-linux-gnu/libc

How to run a haskell file in interpreted mode

僤鯓⒐⒋嵵緔 提交于 2019-11-26 19:13:52
问题 I've been told you can interpret haskell files (which I assume means they will work like Ruby/Python/Perl). Can't find the command line option on ghc to do this, though. It always wants to compile my file. Took a look at ghci as well, but it always dumps me into a repl. I'm basically wanting to just do ghc -i MyFile.hs (where -i is a made up flag that I'm pretending correllates to interpreted mode) and have it execute so that I can get quick feedback while I'm trying out ideas and learning.

GHC's RTS options for garbage collection

人盡茶涼 提交于 2019-11-26 18:49:42
问题 I have a Haskell program which processes a text file and builds a Map (with several million elements). The whole thing can run for 2-3 minutes. I found that tweaking the -H and -A options makes a big difference in running time. There is documentation about this functionality of the RTS, but it's a hard read for me since I don't know the algorithms and terms from GC theory. I'm looking for a less technical explanation, preferably specific to Haskell/GHC. Are there any references about choosing

What is fusion in Haskell?

早过忘川 提交于 2019-11-26 15:58:49
问题 Every now and again I have been noticing the following in Haskell documentation: (for example in Data.Text): Subject to fusion What is fusion and how do I use it? 回答1: In general, fusion refers to transformations whose purpose is to get rid of intermediate data structures. You fuse function calls that result in wasteful memory allocations into something more efficient. This is actually IMO one of the biggest applications of Haskell being pure. And you pretty much don't need to do anything to

Is there a list of GHC extensions that are considered 'safe'?

非 Y 不嫁゛ 提交于 2019-11-26 15:58:16
问题 Occasionally, a piece of code I want to write isn't legal without at least one language extension. This is particularly true when trying to implement ideas in research papers, which tend to use whichever spiffy, super-extended version of GHC was available at the time the paper was written, without making it clear which extensions are actually required. The result is that I often end up with something like this at the top of my .hs files: {-# LANGUAGE TypeFamilies , MultiParamTypeClasses ,

Small Haskell program compiled with GHC into huge binary

╄→尐↘猪︶ㄣ 提交于 2019-11-26 14:52:43
Even trivially small Haskell programs turn into gigantic executables. I've written a small program, that was compiled (with GHC) to the binary with the size extending 7 MB! What can cause even a small Haskell program to be compiled to the huge binary? What, if anything, can I do to reduce this? Don Stewart Let's see what's going on, try $ du -hs A 13M A $ file A A: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.27, not stripped $ ldd A linux-vdso.so.1 => (0x00007fff1b9ff000) libXrandr.so.2 => /usr/lib/libXrandr.so.2