I tried running the tests for Bryan O'Sullivan's Attoparsec-based HTTP parser (http://www.serpentine.com/blog/2010/03/03/whats-in-a-parser-attoparsec-rewired-2/), and I got this error:
> runhaskell TestRFC2616.hs
TestRFC2616.hs:13:30:
Not in scope: `many'
Perhaps you meant one of these:
`any' (imported from Prelude),
`B.any' (imported from Data.ByteString.Char8),
many' (imported from Data.Attoparsec)
Surprised, I ran ghci and got this:
> ghci
GHCi, version 7.6.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> :m +Data.Attoparsec
Prelude Data.Attoparsec> :t many
<interactive>:1:1:
Not in scope: `many'
Perhaps you meant one of these:
`any' (imported from Prelude),
many' (imported from Data.Attoparsec),
`many1' (imported from Data.Attoparsec)
Prelude Data.Attoparsec>
Can anyone tell me what's going on?
This example is 4 years old. In version 0.8.0 there was a implementation of many in the Data.Attoparsec.Combinator module, you can check the source here.
The current version of the library doesn't implements a many function, but it implements a many' function (source here). That's why you ghci give you many' as a suggestion.
The many that was implemented in Data.Attoparsec.Combinator is the same that is implemented in Control.Applicative (see here the implementation of many in the Alternative type class). You probably need to import the Control.Applicative. If that works I would suggest that you make a pull request to solve that issue (the library repository is here)
Related
I am trying to import documentGetElementById function for use in Reflex FRP. I tried the import below but can't find the function (which according to hackage should be there):
GHCi, version 8.0.1: http://www.haskell.org/ghc/ :? for help
[1 of 1] Compiling Main ( Test.hs, interpreted )
Ok, modules loaded: Main.
*Main> import Graphics.UI.Gtk.WebKit.DOM.Document
*Main Graphics.UI.Gtk.WebKit.DOM.Document> :t documentGetElementById
<interactive>:1:1: error:
Variable not in scope: documentGetElementById
I will appreciate help with resolving this. I am running latest Reflex platform build with ghc 8.0.1 on mac where webkit works now. I see the same problem on Linux as well. So, it doesn't seem to be platform-specific.
I also did github code search on ghcjs-dom but documentGetElementById doesn't show up. So, perhaps it has been moved somewhere else?
documentGetElementById has been renamed to getElementById after ghcjs-dom refactoring. So, an import like below would work:
*Main> import Graphics.UI.Gtk.WebKit.DOM.Document
*Main Graphics.UI.Gtk.WebKit.DOM.Document> :t getElementById
getElementById
:: (DocumentClass self, System.Glib.UTFString.GlibString string,
MonadIO m) =>
self -> string -> m (Maybe Graphics.UI.Gtk.WebKit.Types.Element)
A made a module Timeit. I can't import it to GHCi.
Module:
module Timeit (timeit, timeCatch) where
import Data.Time.Clock
timeit::IO ()->IO (Float)
timeit io=do
(time,())<-timeCatch io
return time
timeCatch::IO (a)->IO (Float,a)
timeCatch io=do
start <-getCurrentTime
result <-io
end <-getCurrentTime
return $! (realToFrac (diffUTCTime end start), result)
test=do
putStrLn "What is your name?"
name <- getLine
putStrLn $ "Your name is "++name++"."
GHCi:
theking#ChrisLaptopUbuntu1304:~/Desktop/Haskell$ cd ~/Desktop/Haskell/; ghci
GHCi, version 7.6.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> import Timeit
<no location info>:
Could not find module `Timeit'
Perhaps you meant Time (needs flag -package haskell98-2.0.0.2)
I am able to import it into my other programs, just not GHCi.
Note: Am I a haskell noob.
In order for a module to be imported by GHCi, you have to make sure a few things are true.
First, are you in the same directory? By default GHCi will only search the current directory for modules.
Second, have you added the module header? Your code should start with
module Timeit where
...
Third, your file must actually be named Timeit.hs (with that capitalization).
By default Haskell inserts module Main where, which is a problem if your module isn't main.
Last but not least, GHCi seems to require that you use :l Timeit at least once. I'm not sure why this is, but once loaded you can remove it from scope with :m and then import it to your hearts content.
If you've done these things it should import just fine.
To import modules from ghci don't use import, rather say
:m +TimeIt
*Main> :t putStrn
<interactive>:1:1:
Not in scope: `putStrn'
Perhaps you meant one of these:
`putStr' (imported from Prelude),
`putStrLn' (imported from Prelude)
Please note that I am practising haskell programming in emacs with haskell mode.
Even while using terminal, I am getting following error:
optimight#optimight:~$ ghci
GHCi, version 7.4.1: 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> :set prompt ghci>
ghci>:t putStrln
<interactive>:1:1:
Not in scope: `putStrln'
Perhaps you meant one of these:
`putStrLn' (imported from Prelude),
`putStr' (imported from Prelude)
The I/O action you are looking for is putStrLn. Note the capital L — Haskell symbols are case-sensitive — just before the final n, as in “put a string on a line of its own.”.
This question arose on #haskell irc chat:
How can I start ghci without importing prelude?
The possible answer seemed obvious:
ghci -XNoImplicitPrelude, or load a file with import Prelude ()
The latter seems to work, while the former strangely does not. However, import Prelude () imports the declared instances from Prelude, right? Is there a better way of creating a ghci session without loading Prelude at all?
% ghci
GHCi, version 7.0.4: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading package ffi-1.0 ... linking ... done.
Prelude> :m -Prelude
> :i map
Top level: Not in scope: `map'
> :i Eq
Top level: Not in scope: data constructor `Eq'
However, I'm not sure about the instances and how ghci deals with them.
Is there a particular instance that you're concerned about?
The accepted answer doesn't seem to work anymore. This does work in ghci 8.0.2.
Prelude> :set -XNoImplicitPrelude
Prelude> :m -Prelude
>
Is there a way to specify the package name for a module for the :browse, :load or :module commands in ghci (version 6.12.1) ?
Some module names are ambiguous:
Prelude> :module Control.Monad.Cont
<no location info>:
Ambiguous module name `Control.Monad.Cont':
it was found in multiple packages: mtl-1.1.0.2 monads-fd-0.1.0.2
Is setting the -hide-package option the only thing I can do to avoid the ambiguity?
As far as I know, yes. But it doesn't have to be a big deal, you can do this inside ghci:
Prelude Data.List> :set -hide-package mtl
package flags have changed, resetting and loading new packages...
Prelude> import Control.Monad.Cont
Prelude Control.Monad.Cont>
There was also a line-item on GHC-7 change log that made me think package imports would work on the command line, but it doesn't seem to yet (see below). The change comment said something like "full import syntax supported in GHCi", which must exclude extensions I suppose.
$ ghci-7.0.0.20100924 -XPackageImports
GHCi, version 7.0.0.20100924: http://www.haskell.org/ghc/ :? for help
...
Prelude Data.List> import "mtl" Control.Monad.Cont
<no location info>:
Ambiguous module name `Control.Monad.Cont':
it was found in multiple packages: mtl-1.1.1.0 monads-fd-0.1.0.2
Is setting the -hide-package option the only thing I can do to avoid the ambiguity?
You can use ghc-pkg, e.g.
$ ghc-pkg hide monads-fd
This is like setting -hide-package on every subsequent ghc invocation. Packages explicitly depending on monads-fd via Cabal will not be affected, but everything else is. Watch out!