ghci

Where can I find a full parenthesizer for Haskell?

Is there a way in GHCI to show a fully parenthesized version of a statement? I've found myself wanting to do that sometimes to help me understand a piece of code that I'm not familiar with. Sometimes the conciseness of the masters obscure things for us n00bs, and anything to help me break these beasts apart seems to help. ...

Failed to try function "permutations" in ghci (Haskell)

I am trying to walk through the functions in Data.List of the Haskell stardard library and get an error when trying "permutations". What am I missing here? Thanks. Prelude> map (\b-> b*b) [1,2,3] [1,4,9] Prelude> permutations "abc" <interactive>:1:0: Not in scope: `permutations' ...

how to write numbers in lambda using ghci

Hi. I am new to Haskell, using Ghci. I have a function, called three, that I want to write as let three = \x->(\y->(x(x(x y)))) OK, this works, but when I try three (2+) 4 It does not work. Instead, I get some "cannot construct infinite type" error. Please help me. ...

How to use fromInteger in Haskell?

One way to calculate 2^8 in haskell is by writing product(replicate 8 2) When trying to create a function for this, defined as follows... power1 :: Integer → Integer → Integer power1 n k | k < 0 = error errorText power1 n 0 = 1 power1 n k = product(replicate k n) i get the following error: Couldn't match expected type 'Int' again...

Differences Between Hugs, Yhc and GHCi

There are differences between Hugs, Yhc and GHCi? If there are differences, What are they? ...

How do you route stdin from a file to a function when running GHCI

I'm using ghci 6.10.4 at the dos command line in XP, and also in emacs using haskell-mode-2.4 When running programs that operate on stdin, is there a way I can redirect a file to be stdin? For example if I have a function called main that reads from stdin, I can't do: *Main> main < words.txt Is there another way? Also I would like t...

Haskell List Comprehension

I get the error "Not in scope: x" when doing as follows... blanks :: Sudoku -> [Pos] blanks (Sudoku su) = [ fst x | x <- posSud | isBlank (snd x) ] where isBlank Nothing = True isBlank _ = False posSud = zip ixPos (concat su) ixPos = zip ixRows ixCols ixCols = concat (replicate 9 [0..8]) ixRows ...

How to use 'oneof' in quickCheck (Haskell)

I am trying to write a prop that changes a Sudoku and then checks if it's still valid. However, I am not sure how to use the "oneof"-function properly. Can you give me some hints, please? prop_candidates :: Sudoku -> Bool prop_candidates su = isSudoku newSu && isOkay newSu where newSu = update su aBlank aCandidate aCandi...

Why does ghci say that 1.1 + 1.1 + 1.1 > 3.3 is True?

I've been going through a Haskell tutorial recently and noticed this behaviour when trying some simple Haskell expressions in the interactive ghci shell: Prelude> 1.1 + 1.1 == 2.2 True Prelude> 1.1 + 1.1 + 1.1 == 3.3 False Prelude> 1.1 + 1.1 + 1.1 > 3.3 True Prelude> 1.1 + 1.1 + 1.1 3.3000000000000003 Does anybody know why that is? ...

Can GHCi tell me the type of a local Haskell function?

Is it possible to query the ghci for the type it inferred for a function inside another function? ...

Accessing named fields in a Haskell function

Hi I've defined a Tree data type in Haskell and an associated 'size' method which calculates the number of elements in the tree. This worked before, however I have updated the Tree data type to use named fields as in the following definition: data Tree a = Empty | Leaf {value::a} | Node {left :: (Tree a), value :: a, right :: (Tree a...

GHCi error: Not in scope

I'm trying to compile this function from Learn You a Haskell for Great Good. removeNonUppercase st = [ c | c <- st, c `elem` ['A'..'Z']] by placing it into a removeNonUpperCase.hs file. It compiles fine, but when passing the argument: ghci> removeNonUppercase "Hahaha! Ahahaha!" the compiler says: <interactive>:1:0: Not in ...

How to define a function in ghci across multiple lines?

I'm trying to define any simple function that spans multiple lines in ghci, take the following as an example: let abs n | n >= 0 = n | otherwise = -n So far I've tried pressing Enter after the first line: Prelude> let abs n | n >= 0 = n Prelude> | otherwise = -n <interactive>:1:0: parse error on input `|' I've a...

ghci not loading function from file

In test.hs, I have: doubleMe x = x + x In ghci, I type: Prelude> :l test [1 of 1] Compiling Main ( test.hs, interpreted ) Ok, modules loaded: Main. *Main> doubleMe 9 <interactive>:1:0: Not in scope: `doubleMe' *Main> Why? How to fix? ...

Info on type family instances

Intro: While checking out snoyman's "persistent" library I found myself wanting ghci's (or another tool) assistance in figuring out stuff. ghci's :info doesn't seem to work as nicely with type-families and data-families as it does with "plain" types: > :info Maybe data Maybe a = Nothing | Just a -- Defined in Data.Maybe ... > :inf...

How do I use multiple where clauses in GHCi?

I'm playing around with GHCi for the first time, and I'm having some trouble writing multi-line functions. My code is as follows: Prelude> :{ Prelude| let diffSquares lst = abs $ squareOfSums lst - sumOfSquares lst Prelude| where Prelude| squareOfSums lst = (fst (sumsAndSquares lst))^2 Prelude| sumOfSquares lst = snd (sumsAndS...

How to provide explicit type declarations for functions when using GHCi?

How to I define the equivalent of this function (taken from learnyouahaskell) inside GHCi? import Data.List numUniques :: (Eq a) => [a] -> Int numUniques = length . nub Without the type declaration, GHCi accepts the function definition, but it ends up with an unhelpful type: Prelude Data.List> import Data.List Prelude Data.Li...

How do I get ghci to see packages I installed from cabal?

I've installed the such-and-such a package using cabal, and I can build a program that depends on it using cabal build. But when I load the same program in ghci, ghci complains that it "Could not find module `such-and-such'". I'm surprised this doesn't "just work." How do I tell ghci where to find the packages I've installed with cabal?...

Why can't I define a new type in ghci?

I get an error in ghci when I try to define a new type: Prelude> data Point = Pt Int Int <interactive>:1:0: parse error on input `data' Prelude> let data Point = Pt Int Int <interactive>:1:4: parse error on input `data' What am I doing wrong? ...

Why does this Haskell statement not evaluate lazily?

I have the following function defined: ex 1 x = 1 ex 0 x = 0 ex b x = b ** x Then, when I execute the following: 1 `ex` (sum [1..]) it tries to calculate the sum of the infinite sequence, instead of being lazy and returning 1. Why? EDIT: Upon further investigation, I found that laziness happens if I define the ex function in a ...