ghc

GHC truncating Unicode character output

烂漫一生 提交于 2019-12-12 15:15:04
问题 I can't get GHCi or GHC to print unicode codepoint 221A (sqrt symbol: √). I don't think it's my shell, because I can get ruby to do it: irb> puts "\u221A" √ GHC/GHCi is another issue: ghci> putStrLn "\8730" ghci> withFile "temp.out" WriteMode $ flip hPutStrLn "\8730" ghci> readFile "temp.out" "\SUB\n" So what am I doing wrong? (GHC v6.l0.3) 回答1: GHC's behavior with unicode changed in GHC 6.12.1 to "do the right thing" with Unicode strings. Prior versions truncate to 8 bit characters on IO

Getting the data constructor name as a string using GHC.Generics

倖福魔咒の 提交于 2019-12-12 13:34:17
问题 I'd like something like the following: constrName :: Data a=> a -> String constrName = showConstr . toConstr But for GHC.Generics . I see the Constructor class, but don't see any instances in scope. I'm using base-4.8.1.0 . 回答1: Adapting this gist by Nathan Howell: https://gist.github.com/NathanHowell/6201625 : {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE KindSignatures #-} {-# LANGUAGE TypeSynonymInstances #-} {-# LANGUAGE TypeOperators #-} {-# LANGUAGE

How can I test a new ghc build against stackage

这一生的挚爱 提交于 2019-12-12 13:29:23
问题 I've built ghc-HEAD and I want to try building all of a stackage lts or nightly to see how much it can do. Nothing I say can convince stack to build anything using my new ghc. I try setting up like: stack setup 8.1.20160209 --ghc-variant=aarch64-HEAD --ghc-bindist=https://s3-us-west-1.amazonaws.com/stack-aarch64/ghc-8.1.20160209-aarch64-unknown-linux.tar.xz And then I download an lts config.cabal and copy all of the packages into my.cabal file. This is all that's necessary to build everything

Using `foreign import prim` with a C function using STG calling convention

此生再无相见时 提交于 2019-12-12 11:27:44
问题 I have a simple C routine that takes four words and returns four words, and for which gcc can optimize and emit some primops that GHC doesn't support. I'm trying to benchmark various ways of calling this procedure, and am having trouble trying to adapt the technique described here to use foreign import prim . The following is meant to just add 1 to each input word, but segfaults. Main.hs: {-# LANGUAGE GHCForeignImportPrim #-} {-# LANGUAGE ForeignFunctionInterface #-} {-# LANGUAGE MagicHash #-

How to get around the Coverage Condition for Functional Dependencies without using -XUndecidableInstances

社会主义新天地 提交于 2019-12-12 10:56:25
问题 Wen using functional dependencies, I frequently hit the Coverage Condition . It is possible to lift it with UndecidableInstances , but I usually try to stay away from that extension. Here is a somewhat contrived example, that works without UndecidableInstances : {-# Language MultiParamTypeClasses, FunctionalDependencies, FlexibleInstances #-} data Result = Result String deriving (Eq, Show) data Arguments a b = Arguments a b class Applyable a b | a -> b where apply :: a -> b -> Result instance

Why is there no 'foreign import prim unsafe'?

风流意气都作罢 提交于 2019-12-12 10:36:27
问题 This is a followup to my earlier question here. I've been able to get something working per Reid Barton's answer, but I notice in the core I see __pkg_ccall_GC : case {__pkg_ccall_GC hashabler-2.0.0 sipRound_s_x2 Word# -> Word# -> Word# -> Word# -> (# Word#, Word#, Word#, Word# #)} ww1 ww2 ww3 (xor# ww4 b1) Which is I think what you'd expect for a "safe" ffi call. Yet adding "unsafe" to the foreign import string is not allowed (though the error messages doesn't say why): src/Data/Hashabler

How to force ghc's profiler to step deeper into the libraries?

穿精又带淫゛_ 提交于 2019-12-12 08:54:52
问题 I'm trying to profile my program. So I compile it with -prof and -auto-all flags and run with -P to get detailed profiling report: $ ghc --make -prof -auto-all Test.hs $ ./Test +RTS -P Here is a piece of profiling report: COST CENTRE MODULE no. entries %time %alloc main Main 266 1 0.0 0.0 run Main 273 21845 99.3 99.7 sz Main 274 21844 0.0 0.0 size Main 268 21845 0.7 0.3 It seems that run consumes all time and memory. It calls a lot of functions from various libraries, and I'm quite sure that

Haskell reinstall base with profiling enabled

谁说胖子不能爱 提交于 2019-12-12 08:23:26
问题 I am trying reinstall my Haskell libraries with profiling enabled by following the instructions listed here However, whenever cabal attempts to reinstall one of the libraries I get the following message: LibraryNameHere.hs:1:1: Could not find module `Prelude' Perhaps you haven't installed the profiling libraries for package `base'? Use -v to see a list of the files searched for. When I try to reinstall base with profiling enabled I get the following messages: me@machine:~/.cabal/$ cabal

Can I get warnings about overly-restrictive type signatures?

我们两清 提交于 2019-12-12 08:23:14
问题 Can GHC or some lint tool tell me when I've provided a type signature for a function that could be more polymorphic? 回答1: GHC doesn't do this, and a quick search of Hackage turns up nothing. A simple, but possibly quite effective way to implement such a thing would be to load the module in GHCi, use :browse to get all the type signatures, then load a copy without any type signatures, use :browse again, and compare the two outputs; then just print all the lines that differ beyond parentheses,

Haskell: getting the static type of an expression

久未见 提交于 2019-12-12 07:09:55
问题 I'm looking for a function that does what the GHCi :type command does. Ideally, it would have a signature something like getStaticType :: a -> String a = getStaticType (1+2) -- a = "(Num t) => t" b = getStaticType zipWith -- b = "(a -> b -> c) -> [a] -> [b] -> [c]" (Note: this has nothing to do with Data.Dynamic. I just want the static type inferred from the compiler. In fact the function wouldn't need a runtime implementation at all, as all calls to it could be inlined as constants at