Questions tagged [ghci]

GHCi is the interactive environment (REPL) for the Glasgow Haskell Compiler.

Filter by
Sorted by
Tagged with
1 vote
1 answer
52 views

Why is the type of a function different based on whether it is defined in a file or in GHCi repl?

Why is the type of mth4 is different based on whether it is defined in a file or directly in GHCi repl? Contents of test2.hs: mth1 x y z = x * y * z mth2 x y = \z -> x * y * z mth3 x = \y -> \z -...
peti's user avatar
  • 826
0 votes
0 answers
60 views

Different behavior in GHCI and GHC (Running radare2 pipe)

I am trying to get the example Haskell code of R2Pipe working. I have copied the R2Pipe.hs module file into my project and my main function looks as follows : module Main where import Control....
confusedandsad's user avatar
1 vote
1 answer
48 views

Trigger completion within GHCi when using :main

I'm using the optparse-applicative library, which supports Bash-completion. I'd like to trigger such completion when typing :main <tab> within GHCi. Is there a way to instruct GHCi to use the ...
noteed's user avatar
  • 330
0 votes
0 answers
52 views

ghci not creating new lines (outputs are on the same line too)

I have just got Haskell installed using GHCup in WSL2 (Ubuntu). However, there is a problem with the ghci interpreter. When I start ghci and I press enter, the interpreter doesn't create a new line, ...
asa's user avatar
  • 719
1 vote
0 answers
75 views

run haskell ghci without having admin privilege

I'm setting up the environment to learn haskell and I'm able to compile programs using ghc, however, I can't invoke the ghci interpreter. Below is the error: $ ghci GHCi, version 9.6.2: https://www....
asa's user avatar
  • 719
1 vote
1 answer
31 views

GHC's readBin function from Numeric Library is not being recognised by GHCI

I am trying to use the readBin function from the Numeric Library but ghci is telling me that it is not in scope. Other functions like readOct and readHex are working. What could be the problem here? ...
Taimoor Zaeem's user avatar
2 votes
1 answer
140 views

Haskell implementation of Determinant, Rank and Inverse Matrix calculation- input matrix size limitation

I'm new to Haskell. As a part of an academic course, I was requested to implement a function in Haskell that calculates the determinant, rank and inverse matrix of a given matrix. I use gaussian ...
Menish's user avatar
  • 21
0 votes
1 answer
93 views

A very simple confusion about "let" when assigning variables [duplicate]

The wikibooks Haskell page on variables and functions notes the following: Note The let keyword (a word with a special meaning) lets us define variables directly at the GHCi prompt without a source ...
blex-max's user avatar
1 vote
1 answer
42 views

How to resolve 'Variable not in scope' error when running ghci?

After installing ghci stack, when I run just ghci (version 9.2.7) in terminal and enter some expression such as 1+1 I get the following error: :1:2: error: Variable not in scope: (+) :: t0 -> t1 -&...
CCB's user avatar
  • 131
4 votes
1 answer
88 views

GHCi cannot find documentations

I installed Haskell on Windows using ghcup. While using GHCi, ":doc name" answers back with an error message. Some examples are: ghci> :doc (++) ghc-9.2.5.exe: Can't find any ...
aaay's user avatar
  • 67
2 votes
2 answers
156 views

Strictness and how to tell GHC/GHCi to just store a value in a variable once and for all

Apologies if this is a common question, I couldn't find anything similar, but I may just be too inexperienced to know the proper vocabulary. Here's an example of the fundamental problem in GHCi: -- ...
Syncrossus's user avatar
-1 votes
2 answers
313 views

why i got error while launching stack build?

I am new in haskell programming. For my university project our teacher send us the project and ask us to run these command : "stack init" then "stack build" when i am running stack ...
fera_09's user avatar
0 votes
0 answers
28 views

Error on initial execution of ghci (haskell) [duplicate]

I just installed GHCup from haskell.org. When I execute ghci I receive the following error: GHCi, version 9.2.5: https://www.haskell.org/ghc/ :? for help <no location info>: warning: [-Wmissed-...
kohudson's user avatar
4 votes
2 answers
91 views

Definitions that are implicitly imported to GHCi, even with -XNoImplicitPrelude

When a GHCi session loads a file with {-# LANGUAGE NoImplicitPrelude #-} directive, it will unload most of the Prelude definitions: GHCi, version 8.10.6: https://www.haskell.org/ghc/ :? for help ...
EatChangmyeong's user avatar
0 votes
0 answers
398 views

problem in windows powershell while installing haskell

I try to install haskell in my windows machine, I followed the instructions given in the website of haskell.org, but when I execute in the powerShell as an administrator this commande: Set-...
mimi's user avatar
  • 9
1 vote
1 answer
61 views

Getting `head: empty list` error while trying to transpose a matrix

I wrote this program which is supposed to return the transposition of a matrix of integers. trans:: [[Int]]-> [[Int]] trans [[]]=[[]] trans xss=[(transHead xss)] ++ trans(transTail xss) transHead::...
lilo's user avatar
  • 11
0 votes
0 answers
95 views

Haskell - Variable not in scope: -error for function

I've only been learning Haskell for a week or so, and am currently trying to write a function which returns 0 if the second argument is smaller than the first, and returns the product of the range ...
pickleroll123's user avatar
7 votes
1 answer
79 views

How can I quickly tell how Haskell parses an expression? Is it possible to print the expression with parenthesis around every non-leaf AST node?

Sometimes I run into expressions full of different operators and I have no idea how they get parsed. I know that I can ask GHCi information about an operator with :i, but having to look at multiple ...
Blue Nebula's user avatar
1 vote
1 answer
54 views

Haskell data types with type variables

I have been going through tutorial examples for data types and I have defined the following: ghci> data Animal a b = Cat a | Dog b | Rat ghci> data BreedOfCat = Siamese | Persian | Moggie ghci&...
tanvi's user avatar
  • 27
1 vote
1 answer
48 views

Issues with foldl in ghci

Trying this in ghci: foldl (:) [1] [2,3,4] which gives the following error: <interactive>:51:7: error: • Couldn't match type ‘a’ with ‘[a]’ Expected: [a] -> [[a]] -> [a] ...
tanvi's user avatar
  • 27
0 votes
0 answers
60 views

Getting GHC to print unicode correctly [duplicate]

Using GHC(i) 9.2.5. (Thus, supposedly, after the fix mentioned here), trying to run the following snippet: import Main.Utf8 import GHC.IO.Encoding (getLocaleEncoding) main :: IO () main withUtf8 $ do ...
Arii's user avatar
  • 349
1 vote
1 answer
321 views

Parsing escape characters when creating parser from scratch in Haskell

I have created the code below that is part of building a parser from scratch. I do however encounter unexpected output when using escape characters similar described here ,although my output is ...
Piskator's user avatar
  • 649
2 votes
1 answer
173 views

Haskell FFI: stack run is ok, but GHCi does not link properly

I am trying to learn how to structure a Haskell project/workflow that uses FFI. I am using stack, but I find myself unable to use GHCi when it comes to the imported foreign functions. Here is a ...
Spaghetti's user avatar
0 votes
1 answer
110 views

Error: module ‘main:Course’ is defined in multiple files: src/Course.hs

I'm trying to start working on https://github.com/system-f/fp-course. After running stack ghci, it finishes with: ... [51 of 51] Compiling Test.Loader ( src/Test/Loader.hs, interpreted ) Ok, 51 ...
levant pied's user avatar
  • 3,950
1 vote
1 answer
172 views

How do I import a Haskell package into the REPL for interactive use?

I'm new to Haskell, and have found the :type command in the ghci REPL to be really useful for interactively figuring out how things work. So far I've only used things from the base package, but now I'...
jacobsa's user avatar
  • 5,789
3 votes
2 answers
120 views

What is the meaning of xor = (/=)?

I found the code of logical gate xor written in Haskell, but I don't know what does this "(/=)" mean! xor :: Bool -> Bool -> Bool xor = (/=)
Lokman's user avatar
  • 41
2 votes
1 answer
154 views

newtypes in Haskell with more than one arguments

In Haskell I try to call the following two newtypes that have I have declared. Why does this work: newtype CharList = CharList { get2CharList :: [Char] } deriving (Eq, Show) ghci> CharList &...
Piskator's user avatar
  • 649
2 votes
2 answers
130 views

List comprehension not ending in a square bracket, console freezing

Entering a list comprehension into GHCi does not generate a list, the final square brackets are missing, and the console freezes. This is what I have come up with: [13*x + 3 | x <- [1..], rem (13*x ...
sandy's user avatar
  • 33
0 votes
0 answers
203 views

How to make GHCI put new line before expression result

If I type 1 + 2 into ghci and press enter key, I see this(screenshot below). I would like the result(3 in this case) to be printed on the next line after expression. Is there any way to do this or is ...
farkon00's user avatar
  • 109
0 votes
1 answer
127 views

My Haskell code isn't compiling because of an import error [duplicate]

I'm trying to run my code in my command line to double-check my work. My code works with iHaskell but not with ghci. I'm getting this error: test.hs:6:1: error: parse error on input ‘import’ | 6 | ...
Sam Jones's user avatar
2 votes
1 answer
148 views

Calling a custom monad in haskell using the bind

I am currently 'getting my feet wet with monads' (http://learnyouahaskell.com/a-fistful-of-monads#getting-our-feet-wet-with-maybe) and still struggling with part of this concept. I understand the ...
Piskator's user avatar
  • 649
2 votes
2 answers
383 views

How to configure .ghci file to import all loaded modules

let say I have a project which is just a bunch of Haskell modules with exercises. I'd like to provide a .ghci which automatically imports all modules into ghci scope. The problem is, I can not run ...
lsmor's user avatar
  • 4,963
0 votes
1 answer
126 views

:sprint var is printing _ even after being evaluated [duplicate]

I read Why :sprint always prints a "_"? but I seem to be encountering something else. ghci> sum = foldl (+) 0 ghci> let total = sum [1..1000000] ghci> :sprint total total = _ -- ...
Nero gris's user avatar
  • 562
0 votes
0 answers
172 views

Cabal update now can't load any modules from "hidden packages"

I've been working on a project and recently I did a cabal update. I usually roll into ghci like: $ ghci -package-db ~/.cabal/store/ghc-8.10.7/package.db After the update loading module in my project ...
user2419509's user avatar
0 votes
1 answer
163 views

Having trouble activate Stack

I'm a newbie here also at programming in general. I just installed Stack via curl but got stuck at 'stack setup.' Although the terminal shows the Stack version, it gives me 'zsh: segmentation fault ' ...
Hiraki Takanori's user avatar
1 vote
1 answer
306 views

How can I make Haskell ghci show error messages

Haskell ghci doesn't show error messages, just "error: " without any message. I've looked through documentation and searched the web, but no joy. What am I missing? I'm running on Windows ...
Patrick DeLano's user avatar
1 vote
1 answer
191 views

Function to count number of common vowels in two strings

So I am trying to create a function such that it prints the number of common vowels between the given strings for example common vowels "Hello Joe" "Nice to meet you" would output =...
Liam Neeson's user avatar
1 vote
2 answers
1k views

How do I fix this error when tring to install ghc from ghcub?

Here is the error message: [ Info ] Merging file tree from "C:\ghcup\tmp\ghcup-d5bf0fe7341a" to "C:\ghcup\ghc\8.10.7" [ Warn ] Couldn't remove build dir C:\ghcup\tmp\ghcup-...
ali_r's user avatar
  • 11
2 votes
2 answers
134 views

GHCI needlessly recompiles sub-package

I have a project (let's call it parent) that has a sub-package (child). Using HLS from emacs, whenever I change a file in the parent that imports part of the child package, and try to load it, GHCI ...
Farzad Bekran's user avatar
2 votes
1 answer
919 views

foldr/foldl on pairs seems to ignore first tuple component [duplicate]

I just noticed: foldr (+) 0 (3,7) 7 foldl (+) 0 (3,7) 7 Is this what you'd expect? What is the rationale behind it? ghci --version The Glorious Glasgow Haskell Compilation System, version 9.2.2
stf's user avatar
  • 591
1 vote
1 answer
339 views

How do I use pattern matching in GHCi?

I've got this code: oof [] = 1 oof [(i,j)] = i+j oof [(i,7),(5,j)] = i*j oof (_:_:xs) = foo xs and I typed it into ghci. When I try to execute the expression: oof [(3,7),(5,2)] it should make use of ...
Sten Göring's user avatar
1 vote
1 answer
232 views

show in ghci more or less picky about types

If I fire up ghci and type in a simple arithmetic expression, I usually get the expected result with no fuss GHCi λ: 6 * 7 42 However, I am following the examples in a tutorial which are part of a ...
kewCogs's user avatar
  • 21
1 vote
1 answer
120 views

Haskell -> Printing sortBy list - error: parse error on input ‘print’

I was trying to run this program on ghci, where it reorders the names in the ascending order of their last names. However, when I run it, I get this error " error: parse error on input ‘print’ &...
Tatsunori Ono's user avatar
2 votes
2 answers
100 views

Reverse function behavior in Haskell

digits :: Int -> [Int] digits n = reverse (x) where x | n < 10 = [n] | otherwise = (mod n 10) : (digits (div n 10)) *ghci> digits 1234 = [3,1,2,4]* digits' :: ...
smuthu06's user avatar
1 vote
1 answer
178 views

Defining new types in Haskell

I am pretty new to Haskell, and I was wondering if one can define new types that are defined by lists of other types. For example, I assume a string is defined as a list of characters, so can I define ...
Dani Pedrosa's user avatar
1 vote
2 answers
110 views

Making substring conditions

I'm trying to implement a subString function which has a conditional part: "This function can accept negative start and end position. Negative start position can be considered as zero (e.g. ...
shrike's user avatar
  • 21
0 votes
1 answer
70 views

ghci shows type as being concrete [duplicate]

I have the following code: {-# LANGUAGE GADTs #-} data Exp' a where Float' :: (Num a) => Float -> Exp' a g = Float' 1.2 If I type the above code directly into ghci, and check g's type, I'd ...
darkgrin's user avatar
  • 580
1 vote
2 answers
210 views

Colored ghci output on PowerShell

Some time ago, I stumbled upon this. However, since I'm using Windows, I'm unable to run it. Hence, I decided to create a .ps1 version of it so I would be able to run it in PowerShell. However I've ...
digitalguy99's user avatar
1 vote
1 answer
73 views

How to not display duplicate modules on ghci prompt

Currently this is how my ghci prompt looks like: and I want to make it so that my prompt doesn't display duplicate modules as shown below: but I can't really figure out how. My configuration(ghci....
digitalguy99's user avatar
0 votes
0 answers
326 views

Couldn't import and download Data.List.Ordered in Haskell

I'm too beginner in Haskell and I wrote a simple program that imports Data.List.Ordered, when I run the program this error appears: test.hs:3:1: error: Could not find module `Data.List.Ordered' ...
Reem Aljunaid's user avatar

1
2 3 4 5
22