GHCi error - "Not in scope: `isUpper'" - haskell

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.

Related

(Windows) PutStrLn stops working when inserting code from library

I've noticed some really strange behaviour:
I'm trying to get the haskell z3 bindings to work on windows. But if I insert code from the library into the Main module putStrLn stops working. How can that be?
The Setup
I used the precompiled x64 binary of the z3 solver (z3.4.8.4) for windows (and put it in C:\mylibs\z3-4.8.4_x64).
Then I created a stack project haskellZ3Test
The relevant parts from package.yaml:
dependencies:
- base >= 4.7 && < 5
- z3 <= 408.0
The relevant parts from stack.yaml:
resolver: lts-13.28
packages:
- .
- location:
git: https://github.com/IagoAbal/haskell-z3.git
commit: b10e09b8a809fb5bbbb1ef86aeb62109ece99cae
extra-dep: true
extra-include-dirs:
- "C:\\mylibs\\z3-4.8.4_x64\\include"
extra-lib-dirs:
- "C:\\mylibs\\z3-4.8.4_x64\\bin"
The Problem
Here is Main version 1:
module Main where
import Z3.Monad
main :: IO ()
main = putStrLn "hello world"
If I stack build and then stack exec haskellZ3Test-exe I get hello world on the command line as expected.
However - here is Main version 2:
module Main where
import Z3.Monad
ast :: Z3 AST
ast = do
a <- mkFreshBoolVar "A"
b <- mkFreshBoolVar "B"
mkImplies a b
main :: IO ()
main = putStrLn "hello world"
If I stack build and then stack exec haskellZ3Test-exe now I get nothing ...
Honestly I'm pretty puzzled - compiling and linking seems to work fine.
Any help is highly appreciated. Many thanks in advance.

Haskell error: parse error on input '='

I created a new quick.hs file in the ghci.exe directory. And the content is
quicksort::(Ord a)=>[a]->[a]
quicksort []=[]
quicksort (x:xs)=
let smaller = [a |a<-xs,a<=x]
larger = [a |a<-xs,a>x]
in quicksort smaller ++ [x] ++ quicksort larger
When I issue :l quick in the ghci command lline, the output is
Prelude> :l quick
[1 of 1] Compiling Main ( quick.hs, interpreted )
quick.hs:5:17: error:
parse error on input ‘=’
Perhaps you need a 'let' in a 'do' block?
e.g. 'let x = 5' instead of 'x = 5'
Failed, modules loaded: none.
I have concured this kind of problems many times. What's wrong on earth?
You say in the comments that you are sure there are no tab characters in the source file, but inspecting the source of your question, indeed there is one right before the in token. Replace that with the appropriate number of spaces and you'll be all good.
You have to remove all tabs and change it by spaces. I hope that this instruction helps you.

How to resolve issue with building stream-fusion

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.

Haskell/GHC 7.10.1/Leksah : What is the meaning of this Warning: "name ... found in source file but was not in scope"

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!

Get args Haskell

I'm having problems with an exercise, and can not understand the error.
It should be a simple exercise with args:
import System.IO
import System.Environment
main= do
args < - getArgs
nomeficheiro <- return( args !! 0)
putStrnLn ( "Name is" ++ nomeficheiro)
Then i should run it, with : $ ./comando James
The error:
<interactive>:51:1:
parse error on input ‘$’
Perhaps you intended to use TemplateHaskell
I've read other doubts about args at this fórum and I didn't find any answer that could help me
$ ./comando James isn't meant to be run on GHCi. Instead, $ at the start of the line indicates that the following line should be run in your bash/cmd/shell, not in GHCi:
# in your favourite shell, in the correct directory
./comando James
If you want to run main with arguments within GHCi, you can use :main args:
ghci> :main James
Further remarks
Your current code isn't indented correctly, so make sure that you fix this too. Also, you can use let nomeficheiro = head args instead of … <- return …. Keep in mind that this could lead to problems if one doesn't supply any argument to your program, since head [] calls error.

Resources