ghci

GHCi never loads compiled files

社会主义新天地 提交于 2019-12-07 05:17:44
问题 Write a module: module Foo where foo = 3.14 Compile it: ghc -c Foo.hs Load it: ghci -ignore-dot-ghci GHCi, version 7.8.3: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer-gmp ... linking ... done. Loading package base ... linking ... done. Prelude> :l Foo [1 of 1] Compiling Foo ( Foo.hs, interpreted ) Ok, modules loaded: Foo. Why won't GHCi pick up compiled code? Is it a bug in GHCi? I tried to run with -v , not too helpful. Update

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

Load a module in GHCi by module name when module name doesn't match file name

邮差的信 提交于 2019-12-06 14:54:01
Suppose I am given a source file called MyModule.hs and inside it the module declaration is module My.Module where ... (note: not module MyModule where ... ). I am not permitted to alter this source file or change the directory structure where the file resides. From reading some docs about importing modules in GHCi , it looks like there are ways to import by file name (e.g. either import or :load ), but not any ways to specify a module name that will be searched for in all files of the local directory. Is there a way to import My.Module in GHCi without doing it by specifying the file's name

ghci randomio type inference

你离开我真会死。 提交于 2019-12-06 14:12:57
I am following https://en.wikibooks.org/wiki/Haskell/Understanding_monads/State , and randomIO prints an integer in ghci directly. Given its type is polymorphic, how does ghci know it's Int here? Are there some special rules for type inference in ghci ? GHCi> :m System.Random GHCi> :t randomIO randomIO :: Random a => IO a GHCi> randomIO -1557093684 GHCi> randomIO 1342278538 I suppose it is just simple Monomorphism restriction . Polymorphic types such as Num a => a are handled like Integer if actual type is not specified. Probably this rule also works in ghci and you see integer type instead of

Haskell - How to write (.) f f = (\\x -> f (f x))

笑着哭i 提交于 2019-12-06 10:45:32
I need to write on a module to be run on GHCi, with a function composition to the same function. This (The classic fog(x) = f(g(x)) ) runs: (.) f g = (\x -> f (g x)). The problem appears when I try to write it like this (.) f f = (\x -> f (f x)). (fof(x) = f(f(x))) GHCi says: "Conflicting definitions for `f' Bound at: Lab1.hs:27:9 Lab1.hs:27:12" Line 27:9 appear on the first time f and line 27:12 appear f again. Why doesn't Haskell understand (.) f f = (\x -> f (f x)) ? Will Ness In Haskell, arguments to a function must have unique names. Using the same name for another argument is not allowed

How can I tell which libstdc++ double-conversion wants?

空扰寡人 提交于 2019-12-06 07:27:46
Here's the error I see when trying to load a .hs file into ghci. >Loading package http-enumerator-0.7.1.1 ... linking ... done. >Loading package double-conversion-0.2.0.1 ... can't load .so/.DLL for: stdc++ ?>>> (libstdc++.so: cannot open shared object file: No such file or directory) Further investigation reveals I have multiple stdc++ libraries installed >locate libstdc++.so >/usr/lib/libstdc++.so.6 >/usr/lib/libstdc++.so.6.0.14 >/usr/lib/gcc/x86_64-linux-gnu/4.4/libstdc++.so >/usr/lib32/libstdc++.so.6 >/usr/lib32/libstdc++.so.6.0.14 I thought maybe I could make a symlink to what it wants,

Vim integration with GHCi

点点圈 提交于 2019-12-06 06:51:28
问题 I'm trying to use Vim as a Haskell IDE, and, though I'm not a hardcore Vim user, I enjoy the mode-based way of editing. The only thing I'm missing after my Emacs period is integration with GHCi. In the latter editor you can just type C-c C-l (the same shortcut for all kinds of REPL environments) to reload the current source file and switch to the split window with the interpreter in it. That possibility is indispensable for rapid prototyping, TDD and so on. I'm sure that I've done

How to use 'oneof' in quickCheck (Haskell)

我怕爱的太早我们不能终老 提交于 2019-12-06 03:29:42
问题 I am trying to write a prop that changes a Sudoku and then checks if it's still valid. However, I am not sure how to use the "oneof"-function properly. Can you give me some hints, please? prop_candidates :: Sudoku -> Bool prop_candidates su = isSudoku newSu && isOkay newSu where newSu = update su aBlank aCandidate aCandidate = oneof [return x | x <- candidates su aBlank] aBlank = oneof [return x | x <- (blanks su)] Here are some more info... type Pos = (Int, Int) update :: Sudoku -> Pos ->

Function to evaluate haskell in ghci while editing source file using Emacs

雨燕双飞 提交于 2019-12-06 02:40:49
问题 I'm editing a haskell source file. I want to run my main function in my inferior-haskell buffer (already opened in a different frame) and continue editing my source file. To do this, I do C-c C-l , change frame, main<ret> , change back to original frame This seems quite inefficient. I'd like an emacs function/key that does it one shot. 回答1: There is actually a function to do this already defined in inf-haskell.el : inferior-haskell-load-and-run . This loads your current file and runs :main .

Why does `peek` with a polymorphic Ptr return GHC.Prim.Any when used with a bind?

假装没事ソ 提交于 2019-12-06 02:34:55
Using the low-level GNU Science Library bindings Bindings.Gsl.RandomNumberGeneration , I'm running into this odd type behavior in GHCi where binding changes return type from a peek into GHC.Prim.Any . I'm trying to understand why since I can't use the c'rng_alloc unless I retain the type of pointer to an rng . For eample: λ> :t c'gsl_rng_alloc c'gsl_rng_alloc :: Ptr C'gsl_rng_type -> IO (Ptr C'gsl_rng) λ> :t p'gsl_rng_mt19937 p'gsl_rng_mt19937 :: Ptr (Ptr gsl_rng_type) λ> :t peek p'gsl_rng_mt19937 peek p'gsl_rng_mt19937 :: IO (Ptr gsl_rng_type) λ> x <- peek p'gsl_rng_mt19937 λ> :t x x :: Ptr