ghc

What optimizations can GHC be expected to perform reliably?

别等时光非礼了梦想. 提交于 2019-12-12 07:07:38
问题 GHC has a lot of optimizations that it can perform, but I don't know what they all are, nor how likely they are to be performed and under what circumstances. My question is: what transformations can I expect it to apply every time, or nearly so? If I look at a piece of code that's going to be executed (evaluated) frequently and my first thought is "hmm, maybe I should optimize that", in which cases should my second thought be, "don't even think about it, GHC got this"? I was reading the paper

Run a script (not a module) with ghc

心已入冬 提交于 2019-12-12 04:23:40
问题 Previously I used ghc version < 8 on Linux and when I had a script in a file, say file.hs , like let x = "hello" putStrLn x double x=2*x print $ double 2 double 3 then it was possible to run it and get the outputs in a terminal by doing ghc -e ':script file.hs' Now I'm using ghc 8.0.1 on Windows and this does not work anymore. Is there another way ? I can get the outputs if I open GHCi and type :script file.hs . But I want these outputs in the terminal. I don't know whether this is due to the

How to tell that common subexpression elimination is happening or not in GHC?

半腔热情 提交于 2019-12-12 03:33:24
问题 Let's say I have a naively implemented function like this: quadratic a b c = (ans1, ans2) where ans1 = ((-b) + sqrt (b * b - 4 * a * c)) / (2 * a) ans2 = ((-b) - sqrt (b * b - 4 * a * c)) / (2 * a) There are multiple identical subexpressions. How can I tell without reading core that common subexpression elimination is happening or not and to which parts of this? 回答1: Using trace might tell you as demonstrated in this SO question. import Debug.Trace quadratic a b c = (ans1, ans2) where ans1 =

cross-compiling haskell code through ghc and mingw tools

萝らか妹 提交于 2019-12-12 01:14:45
问题 I've tried -fvia-C and the -pgm s, but none of them manage to create an executable, splurting out lots of errors like Warning: retaining unknown function ``L4' in output from C compiler . 回答1: GHC can't be used as a cross-compiler out of the box. The build system has some support for cross-compilation which we're currently working on improving. For more information, see CrossCompilation on the GHC wiki. I suggest taking further discussion to the glasgow-haskell-users or cvs-ghc mailing lists.

GHC compile DLL for use in VBA

一笑奈何 提交于 2019-12-11 15:45:26
问题 This is an alternative approach to this question here: Export Haskell lib as DLL I am working with GHC version 8.6.1 [latest] and am following the documentation for compiling a DLL from a haskell library for the subsequent use in VBA. My files look like this: Adder.hs: {-# LANGUAGE ForeignFunctionInterface #-} module Adder where adder :: Int -> Int -> IO Int adder x y = return (x+y) foreign export ccall adder :: Int -> Int -> IO Int StartEnd.c: #include <Rts.h> void HsStart() { int argc = 1;

“invalid preprocessing directive” when installing memoize

我是研究僧i 提交于 2019-12-11 14:01:59
问题 I try running: cabal install memoize in the Terminal but all I get is: 11 warnings and 1 error generated. Failed to install memoize-0.6 cabal: Error: some packages failed to install: memoize-0.6 failed during the building phase. The exception was: ExitFailure 1 The 1 error is: Data/Function/Memoize/TH.hs:5:6: error: invalid preprocessing directive #-} ^ 来源: https://stackoverflow.com/questions/23595173/invalid-preprocessing-directive-when-installing-memoize

TypeLit from generic Integer expression

偶尔善良 提交于 2019-12-11 10:47:57
问题 The only way I know to construct a Nat is to use -XDataKinds with promoted integers, i.e., type MyInt = 10 :: Nat . Instead, I'd like to have a function foo :: Integer -> Integer that I can index with a reflected Nat , and then reify the result. To demonstrate what I mean, assume some function mkNat :: Integer -> Q Type . I want to write type Z = $(mkNat $ foo $ natVal (Proxy::Proxy 10)) (In my example, foo is fast enough that it can be computed at compile time without prohibitive overhead.)

Haskell compile time checking of smart constructors

一个人想着一个人 提交于 2019-12-11 10:43:51
问题 I'm learning Haskell, running through the lectures: http://www.cis.upenn.edu/~cis194/spring13/ I've got: module HanoiDisk(HanoiDisk, hanoiDisk) where import Control.Exception data HanoiDisk = HanoiDisk' Integer deriving (Show) hanoiDisk :: Integer -> HanoiDisk hanoiDisk n = assert (n >= 1) $ HanoiDisk' n This works, but if i have: main = do print(show (hanoiDisk (-3)) I only get an error during run-time and not at compile-time. I'm pretty keen to understand how to eliminate run-time

Is it possible to build 64-bit dll on Windows with GHC?

徘徊边缘 提交于 2019-12-11 04:09:21
问题 What I am looking for is exporting my haskell module as a 64-bit dll. My setup is 64-bit Windows 7 and Haskell Platform 2013.2.0.0. I tried building with ghc --make -static -shared -fPIC ff.hs -o ff_dll.dll which works fine except for it produces 32-bit version (I managed to call it from another app). So my question is: is it possible to build 64-bit dll with GHC on Windows? 回答1: You can get a 64-bit GHC from the official GHC website's download section. You can then cabal install haskell

How to replicate the behaviour of 'name in a TH splice

我们两清 提交于 2019-12-11 04:08:32
问题 Consider this Haskell file: {-# LANGUAGE TemplateHaskell #-} {-# OPTIONS_GHC -fplugin Test.Inspection.Plugin #-} module Text (main) where import Test.Inspection import Data.Text as T import Data.Text.Encoding as E import Data.ByteString (ByteString) import Language.Haskell.TH toUpperString :: String -> String toUpperString = T.unpack . T.toUpper . T.pack toUpperBytestring :: ByteString -> String toUpperBytestring = T.unpack . T.toUpper . E.decodeUtf8 do Just n <- lookupValueName