Dimitri DeFigueiredo | 23 Apr 10:23 2014
Picon

why do classes require the type variable in type signatures?

Hello All,

Why does this compile

class Special a where
     isSpecial :: a -> Bool

whereas, GHC 7.6 complains about this

class AlsoSpecial a where
     isAlsoSpecial :: b -> Bool

This is the error message I get:

     The class method `isAlsoSpecial'
     mentions none of the type variables of the class AlsoSpecial a
     When checking the class method:
       isAlsoSpecial :: forall b. b -> Bool
     In the class declaration for `AlsoSpecial'

My question is: Why must I use the type variable of the class 
declaration (i.e. *a*) in the type signature for the associated method? 
Is there a fundamental reason for this or is it just a GHC specific 
limitation? I didn't see a need for it when watching this video

http://channel9.msdn.com/posts/MDCC-TechTalk-Classes-Jim-but-not-as-we-know-them

that explains the translation that GHC does to turn type classes into core.

Thanks!
(Continue reading)

John M. Dlugosz | 22 Apr 20:52 2014
Picon

How to build a package?

I used cabal unpack to get the source of a package to read.  Now I want to make a change. 
  How do I tell Haskell Platform to make that (the same way cabal knows how to) and do so 
with the provided files rather than downloading into temp.
I got a package to work before using Leksah, but I'd like to do it directly since the 
cabal file is present and works just fine.

A related issue: what should I do about the local copy of a module name that is also 
installed?  Can I make my project use that instead, without having to globally change the 
name in all the files?

John M. Dlugosz | 22 Apr 10:00 2014
Picon

How would you write...

chain1 = [ translate x y $ color red $ Circle r | (x,y,r) <- pappus 100 [1..10] ]

The above is not right, as the comprehension syntax doesn't see the input range buried in 
an argument.

What's the right way to express

pap1 = translate x y $ color red $ Circle r
  where (x,y,r) = pappus 100 1

where 1 is [1..10] and I get a list of results?
(pap1 does work as expected)

(1) how can the list comprehension syntax manage it,
(2) what's the recommended way to express that (not necessarily via list comprehension 
syntax) ?

—John

_______________________________________________
Beginners mailing list
Beginners <at> haskell.org
http://www.haskell.org/mailman/listinfo/beginners
Emanuel Koczwara | 21 Apr 21:08 2014
Picon

Haddock and XML

Hi,

I want to include some XML in documentation produced by haddock. Here is
my simple test case:

http://lpaste.net/103047

I generate the docs like this:

haddock -h Doctest.hs

Can I set some command line options or maybe there are some formatting
options (like ' <at> ' in my example) to get this XML rendered correctly?

Emanuel

Attachment (smime.p7s): application/x-pkcs7-signature, 7008 bytes
Hi,

I want to include some XML in documentation produced by haddock. Here is
my simple test case:

http://lpaste.net/103047

I generate the docs like this:

haddock -h Doctest.hs

(Continue reading)

KC | 21 Apr 19:50 2014
Picon

How do I return Nothing from a function?





--

--

Sent from an expensive device which will be obsolete in a few months! :D

Casey

<div><div dir="ltr">
<br><br><br clear="all"><br>-- <br><div dir="ltr">
<p dir="ltr">--<br></p>
<p dir="ltr">Sent from an expensive device which will be obsolete in a few months! :D</p>
Casey<br><br>
</div>
</div></div>
Nishant | 21 Apr 10:06 2014
Picon

Error while using indices and elem


Hi, 

Do I need to define indices and elem for Graph a w here explicitly ? 



import Data.Array

data Graph a w = Array a [(a,w)]
-- array (1,3) [(1,[(2,3),(3,2)])]

--Given a vertex list out adjacents
getAdjVertices :: (Ix a, Eq a) => a -> (Graph a w) -> [a]

getAdjVertices x arr | not (x `elem` (indices arr)) = error "No such Vertex"
                     | otherwise = extractV (arr ! 2)
                     where extractV [] = []
                           extractV (x:xs) = (fst x):extractV (xs)

GHCI gives : 

Prelude> :l programs\graph.hs
[1 of 1] Compiling Main             ( programs\graph.hs, interpreted )

programs\graph.hs:16:47:
    Couldn't match expected type `Array a e0'
                with actual type `Graph a w'
    In the first argument of `indices', namely `arr'
    In the second argument of `elem', namely `(indices arr)'
    In the first argument of `not', namely `(x `elem` (indices arr))'

programs\graph.hs:17:46:
    Couldn't match expected type `Array Integer [(a, b0)]'
                with actual type `Graph a w'
    In the first argument of `(!)', namely `arr'
    In the first argument of `extractV', namely `(arr ! 2)'
    In the expression: extractV (arr ! 2)
Failed, modules loaded: none.
Prelude>


Regards. 
Nishant
<div><div dir="ltr">
<br clear="all"><div>Hi,&nbsp;</div>
<div><br></div>
<div>Do I need to define indices and elem for Graph a w here explicitly ?&nbsp;</div>
<div><br></div>
<div><br></div>
<div><br></div>
<div>
<div>import Data.Array</div>
<div>
<br>
</div>
<div>data Graph a w = Array a [(a,w)]</div>
<div>-- array (1,3) [(1,[(2,3),(3,2)])]</div>
<div><br></div>
<div>--Given a vertex list out adjacents</div>
<div>getAdjVertices :: (Ix a, Eq a) =&gt; a -&gt; (Graph a w) -&gt; [a]</div>
<div><br></div>
<div>getAdjVertices x arr | not (x `elem` (indices arr)) = error "No such Vertex"</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| otherwise = extractV (arr ! 2)</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;where extractV [] = []</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;extractV (x:xs) = (fst x):extractV (xs)</div>
</div>
<div><br></div>
<div>GHCI gives :&nbsp;</div>
<div><br></div>
<div>Prelude&gt; :l programs\graph.hs<br>
</div>
<div>
<div>[1 of 1] Compiling Main &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ( programs\graph.hs, interpreted )</div>
<div><br></div>
<div>programs\graph.hs:16:47:</div>
<div>&nbsp; &nbsp; Couldn't match expected type `Array a e0'</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; with actual type `Graph a w'</div>
<div>&nbsp; &nbsp; In the first argument of `indices', namely `arr'</div>
<div>&nbsp; &nbsp; In the second argument of `elem', namely `(indices arr)'</div>
<div>&nbsp; &nbsp; In the first argument of `not', namely `(x `elem` (indices arr))'</div>
<div><br></div>
<div>programs\graph.hs:17:46:</div>
<div>
&nbsp; &nbsp; Couldn't match expected type `Array Integer [(a, b0)]'</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; with actual type `Graph a w'</div>
<div>&nbsp; &nbsp; In the first argument of `(!)', namely `arr'</div>
<div>&nbsp; &nbsp; In the first argument of `extractV', namely `(arr ! 2)'</div>
<div>&nbsp; &nbsp; In the expression: extractV (arr ! 2)</div>
<div>Failed, modules loaded: none.</div>
<div>Prelude&gt;</div>
</div>
<div><br></div>
<div><br></div>Regards.&nbsp;<br>Nishant
</div></div>
John M. Dlugosz | 21 Apr 06:12 2014
Picon

Where does cabal store its junk?

When I use cabal to “install” a package, where does it end up on my disk?  I can't seem to 
find it.

_______________________________________________
Beginners mailing list
Beginners <at> haskell.org
http://www.haskell.org/mailman/listinfo/beginners
John M. Dlugosz | 21 Apr 06:11 2014
Picon

Re: graphical output?

On 4/20/2014 1:31 AM, Bill Noble wrote:

> (note for some reason I had to install llvm first).
>
I had already tried that, and ran into the same problem.

S. H. Aegis | 20 Apr 14:57 2014
Picon

About scope range: outside of the do-block

I'm trying to solve problem 22 of Euler Project. (http://projecteuler.net/problem=22)

I got file contents using " names <- readFile "names.txt" " in "do-block".
When I try to use 'names' outside of "do-block", I get following error message;
namesScores.hs:30:35: Not in scope: `names'
Failed, modules loaded: none.

Is there any other ways to use variables outside of the "do-block"?
Sorry for taking your time.
Thank you.

My code is...
-------------------------------------------------------------
import Data.List
import Data.List.Split
import Data.Char
import Data.Maybe

main :: IO()
main = do
    names <- readFile "names.txt"
    print $ sum $ map (\x -> getPosition x * getScore x) names

getPosition :: String -> Int
getPosition x = fromMaybe 0 (elemIndex x sortedNamesList) + 1

getScore :: String -> Int
getScore xs = sum $ map (\x -> ord x - 64) xs

sortedNamesList :: [String]
sortedNamesList = sort $ nameList names

nameList :: String -> [String]
nameList = split (dropDelims . dropBlanks $ oneOf ",\"")


Error message is...
------------------------------------------------------------------
Prelude> :l namesScores.hs
[1 of 1] Compiling Main             ( namesScores.hs, interpreted )

namesScores.hs:31:35: Not in scope: `names'
Failed, modules loaded: none.
<div><div dir="ltr">I'm trying to solve problem 22 of Euler Project. (<a href="http://projecteuler.net/problem=22">http://projecteuler.net/problem=22</a>)<div><br></div>
<div>I got file contents using " names &lt;- readFile "names.txt" " in "do-block".</div>
<div>When I try to use 'names' outside of "do-block", I get following error message;</div>
<div>namesScores.hs:30:35: Not in scope: `names'</div>
<div>Failed, modules loaded: none.</div>
<div><br></div>
<div>Is there any other ways to use variables outside of the "do-block"?</div>
<div>Sorry for taking your time.</div>
<div>Thank you.</div>
<div><br></div>
<div>My code is...</div>
<div>-------------------------------------------------------------</div>
<div>
<div>import Data.List</div>
<div>import Data.List.Split</div>
<div>import Data.Char</div>
<div>import Data.Maybe</div>
<div><br></div>
<div>main :: IO()</div>
<div>main = do</div>
<div>&nbsp; &nbsp; names &lt;- readFile "names.txt"</div>
<div>&nbsp; &nbsp; print $ sum $ map (\x -&gt; getPosition x * getScore x) names</div>
<div><br></div>
<div>getPosition :: String -&gt; Int</div>
<div>getPosition x = fromMaybe 0 (elemIndex x sortedNamesList) + 1</div>
<div><br></div>
<div>
getScore :: String -&gt; Int</div>
<div>getScore xs = sum $ map (\x -&gt; ord x - 64) xs</div>
<div><br></div>
<div>sortedNamesList :: [String]</div>
<div>sortedNamesList = sort $ nameList names</div>
<div><br></div>
<div>nameList :: String -&gt; [String]</div>
<div>nameList = split (dropDelims . dropBlanks $ oneOf ",\"")</div>
</div>
<div><br></div>
<div><br></div>
<div>Error message is...</div>
<div>------------------------------------------------------------------</div>
<div>
<div>Prelude&gt; :l namesScores.hs</div>
<div>[1 of 1] Compiling Main &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ( namesScores.hs, interpreted )</div>
<div><br></div>
<div>namesScores.hs:31:35: Not in scope: `names'</div>
<div>Failed, modules loaded: none.</div>
</div>
</div></div>
raffa f | 20 Apr 14:35 2014
Picon

type problems with my little code

hi everyone, i'm a complete beginner on programming and i've been solving the 99 haskell problems and i've come into a situation. just like all my problems with haskell, it's about types. i wrote a little thing that takes a list and puts all the equal characters together, like [1,1,3,2,3] will be [  [1,1],  [3,3], [2]  ]. here it is:

pack xs = pack' xs

         where

         pack' :: [a] -> [[a]]

         pack' [] = []

         pack' (x:y) = extra x xs ++ pack' y 



extra x xs = [sum' (map (remover x) (map ((==) x) xs))]



remover :: a -> Bool -> [a]

remover y x = if x then [y] else []



sum' :: [[a]] -> [a]

sum' [] = []

sum' (x:xs) = x ++ sum' xs


i know, i know, this code is probably terrible and i'm sure there are more clever ways to do this...but i wanna understand what's wrong. the "extra" function works perfectly, it takes a variable and then looks at how many times it's presented on a list and outputs a list with a list of that variable the amount of times that it was presented on the original list.

however, pack does not work quite right. first of all, it'll use extra on repeated characters, creating repeated lists, but that doesn't matter because i have a function that fixes that issue and i'll use it after i figure out what's wrong with pack. now, the real problem is with types. here's what haskell says when i try to load it:

noventa.hs:77:32:
    Couldn't match type `a' with `a1'
      `a' is a rigid type variable bound by
          the inferred type of pack :: [a] -> [[a]] at noventa.hs:73:1
      `a1' is a rigid type variable bound by
           the type signature for pack' :: [a1] -> [[a1]] at noventa.hs:75:19
    Expected type: [a1]
      Actual type: [a]
    In the second argument of `extra', namely `xs'
    In the first argument of `(++)', namely `extra x xs'
    In the expression: extra x xs ++ pack' y
Failed, modules loaded: none.


i don't understand this at all! if i replace [a] with String and [[a]] with [String], it works! but i want pack to work for lists of numbers too... types are so confusing. can anyone help me?
<div><div dir="ltr">hi everyone, i'm a complete beginner on programming and i've been solving the 99 haskell problems and i've come into a situation. just like all my problems with haskell, it's about types. i wrote a little thing that takes a list and puts all the equal characters together, like [1,1,3,2,3] will be [ &nbsp;[1,1], &nbsp;[3,3], [2] &nbsp;]. here it is:<div>
<br>
</div>
<div>
<div>pack xs = pack' xs</div>
<div><br></div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;where</div>
<div><br></div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pack' :: [a] -&gt; [[a]]</div>
<div><br></div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pack' [] = []</div>
<div><br></div>
<div>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pack' (x:y) = extra x xs ++ pack' y&nbsp;</div>
<div><br></div>
<div><br></div>
<div><br></div>
<div>extra x xs = [sum' (map (remover x) (map ((==) x) xs))]</div>
<div><br></div>
<div><br></div>
<div><br></div>
<div>
remover :: a -&gt; Bool -&gt; [a]</div>
<div><br></div>
<div>remover y x = if x then [y] else []</div>
<div><br></div>
<div><br></div>
<div><br></div>
<div>sum' :: [[a]] -&gt; [a]</div>
<div><br></div>
<div>sum' [] = []</div>
<div><br></div>
<div>sum' (x:xs) = x ++ sum' xs</div>
<div><br></div>
</div>
<div><br></div>
<div>i know, i know, this code is probably terrible and i'm sure there are more clever ways to do this...but i wanna understand what's wrong. the "extra" function works perfectly, it takes a variable and then looks at how many times it's presented on a list and outputs a list with a list of that variable the amount of times that it was presented on the original list.</div>
<div><br></div>
<div>however, pack does not work quite right. first of all, it'll use extra on repeated characters, creating repeated lists, but that doesn't matter because i have a function that fixes that issue and i'll use it after i figure out what's wrong with pack. now, the real problem is with types. here's what haskell says when i try to load it:</div>
<div><br></div>
<div>
<div>noventa.hs:77:32:</div>
<div>&nbsp; &nbsp; Couldn't match type `a' with `a1'</div>
<div>&nbsp; &nbsp; &nbsp; `a' is a rigid type variable bound by</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; the inferred type of pack :: [a] -&gt; [[a]] at noventa.hs:73:1</div>
<div>&nbsp; &nbsp; &nbsp; `a1' is a rigid type variable bound by</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;the type signature for pack' :: [a1] -&gt; [[a1]] at noventa.hs:75:19</div>
<div>&nbsp; &nbsp; Expected type: [a1]</div>
<div>&nbsp; &nbsp; &nbsp; Actual type: [a]</div>
<div>&nbsp; &nbsp; In the second argument of `extra', namely `xs'</div>
<div>&nbsp; &nbsp; In the first argument of `(++)', namely `extra x xs'</div>
<div>&nbsp; &nbsp; In the expression: extra x xs ++ pack' y</div>
<div>Failed, modules loaded: none.</div>
</div>
<div><br></div>
<div><br></div>
<div>i don't understand this at all! if i replace [a] with String and [[a]] with [String], it works! but i want pack to work for lists of numbers too... types are so confusing. can anyone help me?</div>
</div></div>
John M. Dlugosz | 20 Apr 05:25 2014
Picon

graphical output?

How might I (easily) use Haskell to draw simple 2D graphics?
Outputting a SVG file is OK for simple static results, but I want to animate.
(Windows platform is strongly preferred.)


Gmane