ghc

Bytestring linking in ghc

谁都会走 提交于 2019-12-07 00:31:52
问题 Consider the following simple code: import Crypto.Hash.SHA1 (hashlazy) import qualified Data.ByteString as BS main = return () I installed cabal install --global bytestring and then I obtain (on a newly installed Ubuntu 12.04 machine using ghc 7.4.1): GHCi runtime linker: fatal error: I found a duplicate definition for symbol fps_minimum whilst processing object file /usr/local/lib/bytestring-0.10.0.1/ghc-7.4.1/HSbytestring-0.10.0.1.o This could be caused by: * Loading two different object

GHC package is hidden

烂漫一生 提交于 2019-12-07 00:28:49
问题 I'm trying to run this simple example that I got from the Haskell wiki. import GHC import GHC.Paths ( libdir ) import DynFlags main = defaultErrorHandler defaultFatalMessager defaultFlushOut $ do runGhc (Just libdir) $ do dflags <- getSessionDynFlags setSessionDynFlags dflags target <- guessTarget "test_main.hs" Nothing setTargets [target] load LoadAllTargets The error messages I'm getting are: amy@wombat$ ghc --make amy15.hs amy15.hs:1:8: Could not find module ‘GHC’ It is a member of the

How can I get `ghci` to use my `show` function?

独自空忆成欢 提交于 2019-12-06 22:20:39
问题 Let's say you want to use your own show function (for example, let show = take 1000 . Prelude.show ). How can you allow ghci to use that for printing instead of the built in show ? 回答1: You can define your own interactive print function e.g: module BetterPrint betterPrint a = putStrLn (take 1000 $ show a) then start ghci as ghci -interactive-print=BetterPrint.betterPrint 来源: https://stackoverflow.com/questions/35613612/how-can-i-get-ghci-to-use-my-show-function

What is the difference between `ioToST` and `unsafeIOToST` from GHC.IO

落花浮王杯 提交于 2019-12-06 19:24:07
问题 What can the differences and intended uses be for ioToST and unsafeSTToIO defined in GHC.IO? -- --------------------------------------------------------------------------- -- Coercions between IO and ST -- | A monad transformer embedding strict state transformers in the 'IO' -- monad. The 'RealWorld' parameter indicates that the internal state -- used by the 'ST' computation is a special one supplied by the 'IO' -- monad, and thus distinct from those used by invocations of 'runST'. stToIO ::

Irrefutable pattern does not leak memory in recursion, but why?

女生的网名这么多〃 提交于 2019-12-06 19:22:55
问题 The mapAndSum function in the code block all the way below combines map and sum (never mind that another sum is applied in the main function, it just serves to make the output compact). The map is computed lazily, while the sum is computed using an accumulating parameter. The idea is that the result of map can be consumed without ever having the complete list in memory, and (only) afterwards the sum is available "for free". The main function indicates that we had a problem with irrefutable

Haskell / GHC — is there any infix tag / pragma for “warn incomplete patterns”

人盡茶涼 提交于 2019-12-06 18:51:45
问题 I'm looking for a pragma that will warn on a particular incomplete pattern. It would make the compiler fail with the following (hypothetical) code: {-# FAILIF incomplete-patterns #-} f :: Int -> Int f 0 = 0 I am trying to write a "compiler" using Arrows, and knowing pattern matching is complete would help isolate bugs. Thanks! 回答1: You can require warnings, including incomplete patterns, with -Wall : {-# OPTIONS_GHC -Wall #-} module A where f :: Int -> Int f 0 = 0 Yielding: A.hs:6:1: Warning:

Are there any advantages of using Rank2Types in favor of RankNTypes?

核能气质少年 提交于 2019-12-06 18:18:11
问题 As far as I know, a decidable type checking algorithm exists (only) for rank-2 types. Does GHC use somehow this fact, and does it have any practical implications? Is there also a notion of principal types for rank-2 types, and a type inference algorithm? If yes, does GHC use it? Are there any other advantages of rank-2 types over rank- n types? 回答1: Rank2Types is a synonym for RankNTypes . So right now there are no advantages of rank-2 over rank-n. 回答2: In principle type checking is decidable

Type Family Shenanigans in GHCi

泄露秘密 提交于 2019-12-06 18:18:05
问题 Here's my code: {-# LANGUAGE TypeFamilies, TypeOperators, DataKinds, PolyKinds, FlexibleContexts, UndecidableInstances #-} module Foo where import Data.Singletons.Prelude import Data.Type.Equality data TP a b -- foldl (\(bool, r) x -> (bool && (r == x), r)) (True, head xs) xs type family Same (b :: Bool) (r :: k) (rq :: [k]) :: k where Same bool r (x ': xs) = Same (bool :&& (r == x)) r xs Same bool r '[] = TP bool r data NotEqualFailure -- converts a True result to a type type family EqResult

On improving Haskell's performance compared to C in fibonacci micro-benchmark

谁说我不能喝 提交于 2019-12-06 17:56:19
问题 I came across this question, which compared the performance of various compilers on computing fibonaci numbers the naive way. I tried doing this with Haskell to see how it compares to C. C code: #include <stdio.h> #include <stdlib.h> int fib (int n) { if (n < 2) return 1; return fib (n-1) + fib (n-2); } int main (int argc, char* argv[]) { printf ("%i\n", fib (atoi(argv[1]))); return 0; } Result: > gcc -O3 main.c -o fib > time ./fib 40 165580141 real 0m0.421s user 0m0.420s sys 0m0.000s Haskell

How do I install dependencies when cross compiling haskell code?

谁都会走 提交于 2019-12-06 17:52:40
问题 I've successfully created a ghc cross compiler, that allows me to compile haskell code for armv6h (raspberry pi in my case) from my x64 linux machine. I've successfully run a hello world program on the raspberry. No I want to build my real app, which has a lot of dependencies on other haskell modules. When I compile for x64 I simply do cabal install dependenciy1 depenency2 ... I know I could make my own programm a cabal-project an automate this step. But that's not the point here. When I try