ghci

Specifying the search path for “load” operations in ghci

本小妞迷上赌 提交于 2019-12-09 11:42:50
问题 In Loading source files it states that the search path for finding source files is specified with the -i option : ghci -idir1:...:dirn Does this mean that when one performs : :load test.hs then ghci looks in the directories above for test.hs? I saw the response at Problem Specifying Source Directory to GHC but I am still not clear about this. For example in Windows XP I put test.hs in : C:\Documents and Settings\winuser\My Documents and then ran : ghci -iC:\Documents and Settings\winuser\My

How can I import a Haskell module in GHCi?

喜夏-厌秋 提交于 2019-12-09 08:03:59
问题 I am trying to teach myself Haskell from the book Learn You A Haskell for Great Good. I got up to the last section of chapter 7 (Modules), where it tells how to create your own module. I did a copy and paste of the Geometry module given in the book at the beginning of the section. The name of the file is Geometry.hs, as the book suggested, and the file is in the bin directory for ghci, which is where I previously was able to successfully do a load using :l for another .hs file. When I type

Non tail-recursive function not blowing up in GHCi. Why?

空扰寡人 提交于 2019-12-08 20:39:53
问题 I was expecting to see my stack blow with the following code.. yet it didn't: *Main> let blowwss x = if x == 0 then 0 else (1 + blowwss (x-1)) *Main> blowwss 1000000 1000000 The function doesn't seem to be tail-recursive, so I'm wondering what may I be missing. Is GHCi's stack bigger than I thought (how can I see it's stack size, btw?). Is it using some kind of trampoline to get over this? Is it smart enough to convert the function to its iterative counterpart? Thanks 回答1: GHCi's stack is

How to force g++ to inline functions?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-08 15:55:39
问题 I have recently encountered an issue with C++ inline functions when using Haskell FFI to C/C++. Namely, g++ does not really inline functions that are declared inline , and generate symbols for them. Ultimately, this generates linker error when ghci tries to load an object file which calls the inline function: Loading object (static) solveeq.o ... done Loading object (dynamic) /usr/lib/gcc/x86_64-linux-gnu/4.6/libstdc++.so ... done final link ... ghc: solveeq.o: unknown symbol `

Mutual recursion in odd/even functions in haskell

限于喜欢 提交于 2019-12-08 15:45:35
问题 In chapter 6 of "Programming in Haskell" by Graham Hutton there is a section called "6.5 Mutual recursion", that contains the following example: even :: Int -> Bool even 0 = True even (n + 1) = odd n odd :: Int -> Bool odd 0 = False odd (n + 1) = even n I wanted to try it out. I put the code in Hof.hs file, ran ghci (version 7.8.3), typed :l Hof.hs and got the following error message Hof.hs:3:7: Parse error in pattern: n + 1 Failed, modules loaded: none. Why am I getting this message? Is the

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

故事扮演 提交于 2019-12-08 07:58:07
问题 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

Changing directories in GHC Monad

☆樱花仙子☆ 提交于 2019-12-08 07:33:02
问题 Looking at ghc package documentation i found this function: workingDirectoryChanged :: GhcMonad m => m () Inform GHC that the working directory has changed. GHC will flush its cache of module locations, since it may no longer be valid. Note: Before changing the working directory make sure all threads running in the same session have stopped. If you change the working directory, you should also unload the current program (set targets to empty, followed by load). I need to run loaded code and

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

*爱你&永不变心* 提交于 2019-12-08 02:41:23
问题 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)) ? 回答1: In Haskell,

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

孤街浪徒 提交于 2019-12-07 23:16:09
问题 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

Can a GHCI config file use CPP macros?

旧时模样 提交于 2019-12-07 10:13:45
问题 I was thinking it would be nice to set up my global GHCI config such that my commonly-used imports occur automatically when the packages that provide them are present. I tried adding this to ~/.ghc/ghci.conf : :set -XCPP #ifdef MIN_VERSION_containers import Data.Set (Set) import qualified Data.Set as Set import Data.Map (Map) import qualified Data.Map as Map #endif But apparently that does not work. > stack repl Configuring GHCi with the following packages: GHCi, version 8.0.2: http://www