ghc

Segfault reading lazy bytestring past 2^18 bytes

这一生的挚爱 提交于 2019-12-08 16:37:19
问题 Consider the following code: http://hpaste.org/90394 I am memory mapping a large 460mb file to a lazy ByteString. The length of the ByteString reports 471053056 . When nxNodeFromID file 110000 is changed to a lower node ID, ie: 10000 , it works perfectly. However; as soon as I try and serialize anything past exactly 2^18 bytes ( 262144 ) of the ByteString I get Segmentation fault/access violation in generated code and termination. I'm running Windows and using GHC 7.4.2. Please advise whether

reallyUnsafePtrEquality# on constructors with no fields

社会主义新天地 提交于 2019-12-08 15:56:21
问题 It's my understanding that the constructors of a type which have no fields are "statically allocated" and GHC shares these between all uses, and that the GC will not move these. If that's correct then I would expect uses of reallyUnsafePtrEquality# on values like False and Nothing to be very safe (no false negatives or positives), because they can only be represented as identical pointers to the single instance of that constructor. Is my reasoning correct? Are there any potential gotchas, or

Is there a way to kill all forked threads in a GHCi session without restarting it?

[亡魂溺海] 提交于 2019-12-08 15:24:55
问题 Based on my previous question I'd like to ask if there's any way to kill all user created threads in a GHCi session? The reason for this is that when a function exits in GHCi the threads that it spawned don't terminate automatically, persisting even through code reloads. Restarting GHCi solves this, but since my application takes a while to load, it would be great if there was a possible (even hacky) workaround. 回答1: No, and actually for almost the same reasons as in How can I build a

Turning a Dict into a constraint

我是研究僧i 提交于 2019-12-08 14:48:47
问题 I have a class Cyc c r which has functions for datas of the form c m r , where m is a phantom type. For example, class Cyc c r where cyc :: (Foo m, Foo m') => c m r -> c m' r I do have good reasons for not making m a class parameter. For the purposes of this example, the primary reason is that it reduces the number of constraints on functions. In my actual example, a more compelling need for this interface is that I work with changing and hidden phantom types, so this interface lets me get a

Is it possible to invert the order errors are displayed?

谁说胖子不能爱 提交于 2019-12-08 14:33:55
问题 When compiling a faulty program with GHC, errors are displayed in ascending line order. That causes the first errors to get pushed up the console, so you need to scroll up if you work by fixing the first errors first, which may be annoying. Is it possible to ask GHC to print errors in descending line order? 回答1: You can do this with the -freverse-errors option flag of the GHC compiler. So you should compile it with: ghc -freverse-errors code.hs Like the documentation says: -freverse-errors

Can using UndecidableInstances pragma locally have global consequences on compilation termination?

纵饮孤独 提交于 2019-12-08 14:27:59
问题 Suppose a Haskell library designer decides to use UndecidableInstances for some reason. The library compiles fine. Now suppose some program uses the library (like defines some instances of its type classes), but doesn't use the extension. Can it happen that the compilation fails (doesn't terminate)? If such a scenario can happen, I'd be happy to see an example. For example, as mtl uses UndecidableInstances a lot, is it possible to write a program that depends on mtl (or any other standard

Changing directories in GHC Monad

☆樱花仙子☆ 提交于 2019-12-08 07:33:02
问题 Looking at ghc package documentation i found this function: workingDirectoryChanged :: GhcMonad m => m () Inform GHC that the working directory has changed. GHC will flush its cache of module locations, since it may no longer be valid. Note: Before changing the working directory make sure all threads running in the same session have stopped. If you change the working directory, you should also unload the current program (set targets to empty, followed by load). I need to run loaded code and

How to use the epoll/kqueue enabled version of GHC/Haskell for network connections?

痞子三分冷 提交于 2019-12-08 04:52:27
There is a lot of old information on the net regarding an epoll/kqueue enabled GHC. For example, the code on the Simple Servers wiki page doesn't compile anymore. Could someone provide a basic example of how to use this feature with a modern GHC version to build, e.g. a TCP server that just responds with "Hello" on connect? GHC's IO manager uses epoll/kqueue under the hood without any special programmer effort. Just write the naive threaded program -- that puts each concurrent blocking IO call in a separate thread -- and GHC will make sure it works out the way you want it to. 来源: https:/

get the renamed (with fully qualified import) haskell AST using ghc api

左心房为你撑大大i 提交于 2019-12-08 04:35:54
问题 I can get the following ghc compiler working using ghc api to compile a single file.I would like to get the renamed AST of haskell source (AST with all function calls fully qualified) ghcmake = defaultErrorHandler defaultFatalMessager defaultFlushOut $ do runGhc (Just GP.libdir) $ do dflags <- getSessionDynFlags setSessionDynFlags dflags target <- guessTarget targetFile Nothing setTargets [target] load LoadAllTargets From this simple demo,the renaming process ought be done in "load" function.

Using a haskell function from C++: Undefined reference error

邮差的信 提交于 2019-12-08 00:21:24
问题 I want to call haskell functions out of C++ and did use the tutorial at http://www.haskell.org/ghc/docs/7.0.2/html/users_guide/ffi-ghc.html So I have a haskell file Foo.hs: module Foo where foreign export ccall foo :: Int -> IO Int foo :: Int -> IO Int foo n = return (length (f n)) f :: Int -> [Int] f 0 = [] f n = n:(f (n-1)) and called ghc Foo.hs which created a Foo_stub.h: #include "HsFFI.h" #ifdef __cplusplus extern "C" { #endif extern HsInt foo(HsInt a1); #ifdef __cplusplus } #endif a Foo