ghci

Using gcc instead of clang in ghci or ghc

核能气质少年 提交于 2019-11-29 14:25:06
问题 On Mac OSX 10.9, the default c compiler bundled with Xcode is clang . I installed gcc-4.9 with homebrew . Now I have two different gcc s, one is clang , the other is gcc . The default is clang . I want to use gcc when compiling Haskell files with ghc , and I want also gcc when I launch ghci . How to do this change? 回答1: Reproducing my directions I've been sharing with haskellers for the past few months via https://gist.github.com/cartazio/7131371 Type ghc --print-libdir The output will be a

Strange Haskell expression with type Num ([Char] -> t) => t

拟墨画扇 提交于 2019-11-29 13:24:28
While doing some exercises in GHCi I typed and got the following> ghci> (1 "one") <interactive>:187:1: No instance for (Num ([Char] -> a0)) arising from a use of ‘it’ In a stmt of an interactive GHCi command: print it which is an error, howeve if I ask GHCi for the type of the expression it does not give any error: ghci> :type (1 "one") (1 "one") :: Num ([Char] -> t) => t What is the meaning of (1 "one") ? Why does this expression gives an error, but GHCi tells it is well typed? What is the meaning of Num ([Char] -> t) => t ? Thanks. Haskell Report to the rescue! (Quoting section 6.4.1 ) An

How does GHCi pick names for type variables?

人走茶凉 提交于 2019-11-29 06:09:21
When using the interactive GHC interpreter, it's possible to ask for the inferred type of an expression: Prelude> :t map map :: (a -> b) -> [a] -> [b] It seems that it takes the names of the type variables from the signature since map is defined as map :: (a -> b) -> [a] -> [b] map _ [] = [] map f (x:xs) = f x : map f xs in the Prelude. That makes a lot of sense! My question is: how are type variable names picked when there is no signature given? An example would be Prelude> :t map fst map fst :: [(b, b1)] -> [b] where it picked names b and b1 . It's clear that renaming must take place, but

Is there a way to limit the memory, ghci can have?

南笙酒味 提交于 2019-11-29 03:41:20
I'm used to debug my code using ghci. Often, something like this happens (not so obvious, of course): ghci> let f@(_:x) = 0:1:zipWith(+)f x ghci> length f Then, nothing happens for some time, and if I don't react fast enough, ghci has eaten maybe 2 GB of RAM, causing my system to freeze. If it's too late, the only way to solve this problem is [ALT] + [PRINT] + [K]. My question: Is there an easy way to limit the memory, which can be consumed by ghci to, let's say 1 GB? If limit is exceed, the calculation should ve aborted or ghci should be killed. Bas Bossink A platform independant way to

Haskell line of code not compiling: “Illegal datatype context”

寵の児 提交于 2019-11-29 02:24:49
问题 I am not able to get this line of code compiled in Haskell but it works on my professor's system. I use ghci version 7.6.2. data Eq a => Shape a = Shape a More precisely, this is the error I am getting [1 of 1] Compiling Main ( test.hs, interpreted ) test.hs:1:6: Illegal datatype context (use -XDatatypeContexts): Eq a => Failed, modules loaded: none. What is the mistake here? Thanks 回答1: Your professor is probably using an older version of GHC. The line you posted uses a feature which has

IO/Monadic assign operator causing ghci to explode for infinite list

别说谁变了你拦得住时间么 提交于 2019-11-29 01:22:36
Consider the following program. It runs forever and does nothing useful, but the memory consumption in ghci is constant : --NoExplode.hs module Main (main) where test :: [Int] -> IO() test lst = do print "test" rList lst rList :: [Int] -> IO () rList [] = return () rList (x:xs) = do rList xs main = do test [1..] Now consider the following trivially modified version of the above. When this program is run in ghci the memory explodes. The only difference is that print "test" is now assigned to x in the do block of test . --Explode.hs module Main (main) where test :: [Int] -> IO() test lst = do x

How can I load optimized code in GHCI?

↘锁芯ラ 提交于 2019-11-29 01:00:03
问题 I am writing a module that relies on optimization. I want to test this module in ghci. But starting ghc in --interactive mode automatically disables optimization; if I compile the module with -O and then try to load it in an interactive session, ghc insists on loading it in interpreted mode. For a simple test case to distinguish optimized and unoptimized modules, isOptimized below evaluates to True with optimization on, but False with optimization off: isOptimized :: Bool isOptimized = g g ::

How to configure GHCi to automatically import modules

假如想象 提交于 2019-11-28 18:35:19
问题 When I use GHCi, I almost always end up importing Control.Applicative , Data.List , etc. . Is there a way to configure GHCi to automatically import those modules. Also, after importing them, how do I keep the prompt from being insanely long? Prelude Control.Applicative Data.List Database.HDBC Database.HDBC.Sqlite3 System.Directory> 回答1: GHCi looks for its configuration file at ~/.ghc/ghci.conf on Unix-like systems. %APPDATA%\ghc\ghci.conf on Windows. The configuration file syntax is simple:

I taught ghci to compile my StackOverflow posts. Can I make it slicker?

眉间皱痕 提交于 2019-11-28 18:13:39
Haskell Stack Overflow layout preprocessor module StackOverflow where -- yes, the source of this post compiles as is Skip down to What to do to get it working if you want to play with this first (1/2 way down). Skip down to What I would like if I witter on a bit and you just want to find out what help I'm seeking. TLDR Question summary: Can I get ghci to add filename completion to the :so command I defined in my ghci.conf ? Could I somehow define a ghci command that returns code for compilation instead of returning a ghci command, or does ghci instead have a better way for me to plug in