ghc

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

霸气de小男生 提交于 2019-12-18 07:40:56
问题 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

How to define function only for old versions in GHC?

有些话、适合烂在心里 提交于 2019-12-18 06:59:17
问题 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? 回答1: You can always write import Prelude hiding (fromRight) which is valid even if fromRight does not exist in

Are Haskell FlexibleInstances a stable extension to the language?

柔情痞子 提交于 2019-12-18 05:27:20
问题 What is the problem with FlexibleInstances in Haskell? Why are they not included in Haskell 2010? Were implementations of FlexibleInstances simply not stable enough for inclusion into a standard or are deeper concerns connected to FlexibleInstances? Is it safe to use them? Will they likely be included in Haskell Prime? 回答1: Is it safe to use them? Yes. FlexibleInstances will not create an ambiguous or overlapping situation when GHC needs to resolve type classes. Note that the potential for

Converting IEEE 754 floating point in Haskell Word32/64 to and from Haskell Float/Double

无人久伴 提交于 2019-12-17 22:44:17
问题 Question In Haskell, the base libraries and Hackage packages provide several means of converting binary IEEE-754 floating point data to and from the lifted Float and Double types. However, the accuracy, performance, and portability of these methods are unclear. For a GHC-targeted library intended to (de)serialize a binary format across platforms, what is the best approach for handling IEEE-754 floating point data? Approaches These are the methods I've encountered in existing libraries and

Make GHC only type-check?

风流意气都作罢 提交于 2019-12-17 22:38:07
问题 Is there a way, either standard, or a clever hack, to make invoking GHC on a file only run the type-checker? E.g. $ ghc --just-check-the-types x.hs $ No output files, no .hi or .o, etc. Don't want to/can't use the GHC API. Just talking about the command-line program, here. 回答1: What about ghc -fno-code file.hs . It will generate no other files and will show errors if your files don't typecheck. Caveat: this will not do analysis on in-exhaustive pattern matches, so if you want those additional

Can GHC really never inline map, scanl, foldr, etc.?

非 Y 不嫁゛ 提交于 2019-12-17 22:30:46
问题 I've noticed the GHC manual says "for a self-recursive function, the loop breaker can only be the function itself, so an INLINE pragma is always ignored." Doesn't this say every application of common recursive functional constructs like map , zip , scan* , fold* , sum , etc. cannot be inlined? You could always rewrite all these function when you employ them, adding appropriate strictness tags, or maybe employ fancy techniques like the "stream fusion" recommended here. Yet, doesn't all this

Making small haskell executables?

邮差的信 提交于 2019-12-17 21:49:25
问题 Are there any good ways to make small haskell executables? With ghc6 a simple hello world program seems to come to about 370kB (523kB before strip). Hello world in C is about 4kB (9kB before strip). 回答1: With the development branch of GHC (anyone know exactly which version this was added in?): $ ghc -o hello hello.hs $ strip -p --strip-unneeded --remove-section=.comment -o hello-small hello $ du hello hello-small 700 hello 476 hello-small Add the -dynamic flag for a dynamically linked RTS: $

Good introductory text about GHC implementation?

我的未来我决定 提交于 2019-12-17 21:25:09
问题 When programming in Haskell (and especially when solving Project Euler problems, where suboptimal solutions tend to stress the CPU or memory needs) I'm often puzzled why the program behaves the way it is. I look at profiles, try to introduce some strictness, chose another data structure, ... but mostly it's groping in the dark, because I lack a good intuition. Also, while I know how Lisp, Prolog and imperative languages are typically implemented, I have no idea about implementing a lazy

Incomplete type signature

允我心安 提交于 2019-12-17 20:19:29
问题 Lets say we've got a function like f below, that returns a monad. However, where you see Int , pretend it's a really complicated type. f :: (Monad m) => m Int -- Pretend this isn't Int but something complicated f = return 42 Now lets say we want to force this into the Maybe monad. We don't need to write the full type of f to do this, we can just do the following: g :: Maybe a -> Maybe a g = id main = print $ (g f) The dummy function g forces f to become Maybe . I think the above is rather

How to compile Haskell to a static library?

邮差的信 提交于 2019-12-17 17:45:10
问题 Hey, I'm learning Haskell and I'm interested in using it to make static libraries for using in Python and probably C. After some googling I found out how to get GHC to output a shared object, but it dynamically depends on GHC`s libraries. The resulting ELF from compiling in GHC is dynamically dependand only on C libs and it's a bit under a MB in size - it has been statically linked with GHC`s libs. How and if can this be achieved for shared objects? Example of current state: $ ghc --make