I'm trying to bring in the stream-fusion library into my project. I am using Stack (LTS 5.16). I added the stream-fusion-0.1.2.5 version to my project's cabal file and also as an extra-dependency in my stack.yaml.
However, when I try to build the project I now get the following:
stream-fusion-0.1.2.5: configure
stream-fusion-0.1.2.5: build
-- While building package stream-fusion-0.1.2.5 using:
/Users/me/.stack/setup-exe-cache/x86_64-osx/setup-Simple-Cabal-1.22.5.0-ghc-7.10.3 --builddir=.stack-work/dist/x86_64-osx/Cabal-1.22.5.0 build --ghc-options " -ddump-hi -ddump-to-file"
Process exited with code: ExitFailure 1
Logs have been written to: /Users/me/Haskell/hqfl/.stack-work/logs/stream-fusion-0.1.2.5.log
Configuring stream-fusion-0.1.2.5...
Building stream-fusion-0.1.2.5...
Preprocessing library stream-fusion-0.1.2.5...
[1 of 3] Compiling Data.Stream ( Data/Stream.hs, .stack-work/dist/x86_64-osx/Cabal-1.22.5.0/build/Data/Stream.o )
/private/var/folders/q_/qbq9bct96jj8p_c9kqbhmt840000gn/T/stack6002/stream-fusion-0.1.2.5/Data/Stream.hs:591:5: Warning:
Pattern match(es) are non-exhaustive
In an equation for ‘next’:
Patterns not matched: (_ :!: (Just (L _))) :!: S2
[2 of 3] Compiling Data.List.Stream ( Data/List/Stream.hs, .stack-work/dist/x86_64-osx/Cabal-1.22.5.0/build/Data/List/Stream.o )
/private/var/folders/q_/qbq9bct96jj8p_c9kqbhmt840000gn/T/stack6002/stream-fusion-0.1.2.5/Data/List/Stream.hs:235:1: Warning:
The import of ‘seq, Int’ from module ‘Prelude’ is redundant
/private/var/folders/q_/qbq9bct96jj8p_c9kqbhmt840000gn/T/stack6002/stream-fusion-0.1.2.5/Data/List/Stream.hs:1703:10: Warning: Tab character
/private/var/folders/q_/qbq9bct96jj8p_c9kqbhmt840000gn/T/stack6002/stream-fusion-0.1.2.5/Data/List/Stream.hs:2496:1: Warning:
Rule "genericSplitAt -> fusible" may never fire
because ‘genericSplitAt’ might inline first
Probable fix: add an INLINE[n] or NOINLINE[n] pragma on ‘genericSplitAt’
/private/var/folders/q_/qbq9bct96jj8p_c9kqbhmt840000gn/T/stack6002/stream-fusion-0.1.2.5/Data/List/Stream.hs:2504:1: Warning:
Rule "genericSplitAt -> splitAt/Int" may never fire
because ‘genericSplitAt’ might inline first
Probable fix: add an INLINE[n] or NOINLINE[n] pragma on ‘genericSplitAt’
/private/var/folders/q_/qbq9bct96jj8p_c9kqbhmt840000gn/T/stack6002/stream-fusion-0.1.2.5/Data/List/Stream.hs:2516:1: Warning:
Rule "genericReplicate -> replicate/Int" may never fire
because ‘genericReplicate’ might inline first
Probable fix: add an INLINE[n] or NOINLINE[n] pragma on ‘genericReplicate’
[3 of 3] Compiling Control.Monad.Stream ( Control/Monad/Stream.hs, .stack-work/dist/x86_64-osx/Cabal-1.22.5.0/build/Control/Monad/Stream.o )
/private/var/folders/q_/qbq9bct96jj8p_c9kqbhmt840000gn/T/stack6002/stream-fusion-0.1.2.5/Control/Monad/Stream.hs:136:10:
Ambiguous occurrence ‘MonadPlus’
It could refer to either ‘Control.Monad.Stream.MonadPlus’,
defined at Control/Monad/Stream.hs:124:1
or ‘GHC.Base.MonadPlus’,
imported from ‘GHC.Base’ at Control/Monad/Stream.hs:80:1-15
/private/var/folders/q_/qbq9bct96jj8p_c9kqbhmt840000gn/T/stack6002/stream-fusion-0.1.2.5/Control/Monad/Stream.hs:140:10:
Ambiguous occurrence ‘MonadPlus’
It could refer to either ‘Control.Monad.Stream.MonadPlus’,
defined at Control/Monad/Stream.hs:124:1
or ‘GHC.Base.MonadPlus’,
imported from ‘GHC.Base’ at Control/Monad/Stream.hs:80:1-15
How can I resolve the ambiguity here?
you need to change the following imports in Control.Monad.Stream (line 80)
- import GHC.Base
+ import GHC.Base hiding ( MonadPlus
+ , (=<<)
+ , ap
+ , join
+ , liftM
+ , liftM2
+ , liftM3
+ , liftM4
+ , liftM5
+ , mapM
+ , mplus
+ , mzero
+ , sequence
+ , when
+ )
Then it compiles - I don't know wether it will work as expected, this library is quite old (3 years as of now) and the tested-with section in the cabal file says 7.6.1. - I recommend using benchmarks to ensure that the benefits you hope to get from this library are real. I would guess that a lot of the ideas of this library have made it into base by now.
Could you leave a comment after you have done these benchmarks I would really be interested in them.
Related
I am trying to use hint package from hackage to create a simple environment where user can issue lines of code for evaluation (like in ghci). I expect some of the input lines to be erroneous (eval would end the session with an error). How can I create a robust session that ignores erroneous input (or better: it reports an error but can accept other input) and keeps the previously consistent state?
Also, I would like to use it in do style, i.e. let a = 3 as standalone input line makes sense.
To clarify things: I have no problem with a single eval. What I would like to do, is allow continuing evaluation even after some step failed. Also I would like to incrementally extend a monadic chain (as you do in ghci I guess).
In other words: I want something like this, except that I get to evaluate 3 and don't stop at undefined with the error.
runInterpreter $ setImports [ "Prelude" ] >> eval "undefined" >> eval "3"
More specifically I would like something like this to be possible:
runInterpreter $ setImports ... >> eval' "let a = (1, 2)" -- modifying context
>> typeOf "b" -- error but not breaking the chain
>> typeOf "a" -- (Num a, Num b) => (a, b)
I don't expect it to work this straightforwardly, this is just to show the idea. I basically would like to build up some context (as you do in ghci) and every addition to the context would modify it only if there is no failure, failures could be logged or explicitly retrieved after each attempt to modify the context.
You didn't show any code so I don't know the problem. The most straight-forward way I use hint handles errors fine:
import Language.Haskell.Interpreter
let doEval s = runInterpreter $ setImports ["Prelude"] >> eval s
has resulted in fine output for me...
Prelude Language.Haskell.Interpreter> doEval "1 + 2"
Right "3"
Prelude Language.Haskell.Interpreter> doEval "1 + 'c'"
ghc: panic! (the 'impossible' happened)
(GHC version 7.10.2 for x86_64-apple-darwin):
nameModule doEval_a43r
... Except that now the impossible happens... that's a bug. Notice you are supposed to get Left someError in cases like these:
data InterpreterError
= UnknownError String
| WontCompile [GhcError]
| NotAllowed String
| GhcException String
-- Defined in ‘hint-0.4.2.3:Hint.Base’
Have you looked through the ghchq bug list and/or submitted an issue?
EDIT:
And the correct functionality is back, at least as of GHC 7.10.3 x64 on OS X with hint version 0.4.2.3. In other words, it appears the bug went away from 7.10.2 to 7.10.3
The output is:
Left (WontCompile [GhcError {errMsg = ":3:3:\n No instance for (Num Char) arising from a use of \8216+\8217\n In the expression: 1 + 'c'\n In an equation for \8216e_11\8217: e_11 = 1 + 'c'\n In the first argument of \8216show_M439719814875238119360034\8217, namely\n \8216(let e_11 = 1 + 'c' in e_11)\8217"}])
Though executing the doEval line twice in GHCi does cause a panic, things seem to work once in the interpreter and properly regardless when compiled.
I am trying to figure out how can i take the progress info from a Progress type (in Development.Shake.Progress) to output it before executing a command. The possible desired output would be:
[1/9] Compiling src/Window/Window.cpp
[2/9] Compiling src/Window/GlfwError.cpp
[3/9] Compiling src/Window/GlfwContext.cpp
[4/9] Compiling src/Util/MemTrack.cpp
...
For now i am simulating this using some IORef that keeps the total (initially set to the sum of the source files) and a count that i increase before executing each build command, but this seems like a hackish solution to me.
On top of that this solution seems to work correctly on clean builds, but misbehaves on partial builds as the sum that displayed is still the total of all the source files.
With access to a Progress data type i will be able to calculate this fraction correctly using its countSkipped, countBuild, and countTodo members (see Progress.hs:53), but i am still not sure how i can i achieve this.
Any help is appreciated.
Values of type Progress are currently only available as an argument to the function stored in shakeProgress. You can obtain the Progress whenever you want with:
{-# LANGUAGE RecordWildCards #-}
import Development.Shake
import Data.IORef
import Data.Monoid
import Control.Monad
main = do
ref <- newIORef $ return mempty
shakeArgs shakeOptions{shakeProgress = writeIORef ref} $ do
want ["test" ++ show i | i <- [1..5]]
"test*" %> \out -> do
Progress{..} <- liftIO $ join $ readIORef ref
putNormal $
"[" ++ show (countBuilt + countSkipped + 1) ++
"/" ++ show (countBuilt + countSkipped + countTodo) ++
"] " ++ out
writeFile' out ""
Here we create an IORef to squirrel away the argument passed to shakeProgress, then retrieve it later when running the rules. Running the above code I see:
[1/5] test5
[2/5] test4
[3/5] test3
[4/5] test2
[5/5] test1
Running at a higher level of parallelism gives less precise results - initially there are only 3 items in todo (Shake increments countTodo as it finds items todo, and spawns items as soon as it knows about any of them), and there are often two rules running at the same index (there is no information about how many are in progress). Given knowledge of your specific rules, you could refine the output, e.g. storing an IORef you increment to ensure the index was monotonic.
The reason this code is somewhat convoluted is that the Progress information was intended to be used for asynchronous progress messages, although your approach seems perfectly valid. It may be worth introducing a getProgress :: Action Progress function for synchronous progress messages.
I am using the Leksah IDE 0.15.0.1 and I get a warning when compiling the example package: "name ... found in source file but was not in scope".
What is the meaning of this Warning ?
I googled for this text but found noting enlightening.
The problem probably lies within the lines
testMain = do
allPass <- $quickCheckAll
unless allPass exitFailure
According to the QuickCheck documentation, in order to utilize quickCheckAll, the IO action that performs $quickCheckAll must have return [] before its definition.
To use quickCheckAll, add a definition to your module along the lines of
return []
runTests = $quickCheckAll
and then execute runTests.
So applying it to your testMain definition, it would end up being
return []
testMain = do
allPass <- $quickCheckAll
unless allPass exitFailure
The documentation also provides an explanation for such need:
Note: the bizarre return [] in the example above is needed on GHC 7.8 and > later; without it, quickCheckAll will not be able to find any of the
properties. For the curious, the return [] is a Template Haskell
splice that makes GHC insert the empty list of declarations at that
point in the program; GHC typechecks everything before the return []
before it starts on the rest of the module, which means that the later
call to quickCheckAll can see everything that was defined before the
return []. Yikes!
I'm learning haskell and I'm trying to write some simple functions. Everything worked well until I've used function isUpper. I'm unable to compile the project because of this error:
[1 of 1] Compiling Main ( C:\Users\...\src\Main.hs, interpreted )
C:\Users\...\src\Main.hs:147:25:
Not in scope: `isUpper'
Failed, modules loaded: none.
Prelude>
My code:
module Main where
main::IO()
main = undefined
stringIsUpper [] = True
stringIsUpper (x:ys) = (isUpper x) && (stringIsUpper(ys))
The goal of this code should be just to check if the inserted string consists of the uppercase letters.
I'm using EclipseFP for development
Thank you for your help
You need to import Data.Char to get isUpper.
EDIT: Solution: The solution to the problem was to specify the correct vector library in a .cabal file. The tell-tale sign (kindly pointed out by #Daniel below) was that the exact version of the vector was referenced in the error message. Indeed my file was building against vector-0.10.something while vector-fftw was compiled against vector-0.9.1.
I am trying to use the fftw-vector library but am stuck with this type error:
-- test.hs
import qualified Numeric.FFT.Vector.Invertible as FFTI
import qualified Data.Vector.Unboxed as U
z = FFTI.run FFTI.dct1 U.empty
main = putStrLn "Won't compile"
This is the error message:
No instance for (vector-0.9.1:Data.Vector.Generic.Base.Vector
U.Vector Double)
arising from a use of `FFTI.run'
Possible fix:
add an instance declaration for
(vector-0.9.1:Data.Vector.Generic.Base.Vector U.Vector Double)
In the expression: FFTI.run FFTI.dct1 U.empty
In an equation for `z': z = FFTI.run FFTI.dct1 U.empty
but as far as I can tell there is actually an instance of Data.Vector.Gener.Base.Vector for Data.Vector.Unboxed Double (Link) (guess I am wrong).
This is with ghc-7.6.1, vector-0.9.1 and vector-fftw.
(I had to make two tiny changes to vector-fftw so it compiles with base 4.6 and ghc-7.6.1, but that should be unrelated ...)
thank you
EDIT:
two changes I made to vector-fftw:
--- a/Numeric/FFT/Vector/Base.hsc
+++ b/Numeric/FFT/Vector/Base.hsc
## -34,10 +34,11 ## import Control.Monad.Primitive (RealWorld,PrimMonad(..),
import Control.Monad(forM_)
import Foreign (Storable(..), Ptr, unsafePerformIO, FunPtr,
ForeignPtr, withForeignPtr, newForeignPtr)
-import Foreign.C (CInt, CUInt)
+-- import Foreign.C (CInt, CUInt)
import Data.Bits ( (.&.) )
import Data.Complex(Complex(..))
import Foreign.Storable.Complex()
+import Foreign.C.Types
diff --git a/vector-fftw.cabal b/vector-fftw.cabal
index 5ca7c46..0436834 100644
--- a/vector-fftw.cabal
+++ b/vector-fftw.cabal
## -40,7 +40,7 ## Library
Other-modules:
Numeric.FFT.Vector.Base
- Build-depends: base>=4.3 && < 4.6, vector==0.9.*, primitive==0.4.*,
+ Build-depends: base>=4.3 && < 4.7, vector==0.9.*, primitive>=0.4 && < 0.6,
storable-complex==0.2.*
Note that the error message specifies the specific version of the package that defines the class an instance is missing for:
No instance for (vector-0.9.1:Data.Vector.Generic.Base.Vector
U.Vector Double)
That usually means that one of the used packages was compiled against a different version than the one currently used in the project.
I don't see how exactly this would arise, but check for broken packages with ghc-pkg check, and verify that your packages have the correct ids with ghc-pkg describe vector and ghc-pkg describe vector-fftw, possibly vector was rebuilt after building vector-fftw. and the package hashes do not match.