Send Beginners mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Linebreaks in lhs2tex eval
      (Sumit Sahrawat, Maths & Computing, IIT (BHU))
   2.  Type declaration (Christian Sperandio)
   3. Re:  Type declaration (Brandon Allbery)
   4.  Operator orders affect parse result (m00nlight)
   5. Re:  Operator orders affect parse result (Francesco Ariis)


----------------------------------------------------------------------

Message: 1
Date: Sun, 12 Apr 2015 21:09:33 +0530
From: "Sumit Sahrawat, Maths & Computing, IIT (BHU)"
        <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Linebreaks in lhs2tex eval
Message-ID:
        <CAJbEW8OumVHthHZ+tUr2p7cy=kv02hx3ak9wv3e_xw44fey...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Try opening an issue here: https://github.com/kosmikus/lhs2tex/issues.

On 12 April 2015 at 17:25, martin <[email protected]> wrote:

> Hello all,
>
> it appears lhs2tex's \eval command does not show linebreaks. This is a
> pity, particularly when the output is formatted
> with a pretty printer.
>
> Is there a way to teach \eval to respect the linebreaks?
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>



-- 
Regards

Sumit Sahrawat
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20150412/00a2908d/attachment-0001.html>

------------------------------

Message: 2
Date: Sun, 12 Apr 2015 18:41:50 +0200
From: Christian Sperandio <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: [Haskell-beginners] Type declaration
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"

Hi,

I?m currently playing with the mutable array to implement an heap sort sort 
(from The Art of Computer Programming) and I?m puzzled with an error.

When I code:

toHeap :: Ord a => [a] -> IO [a]
toHeap [] = return []
toHeap [x] = return [x]
toHeap xs = do
  arr <- newListArray (1, length xs) xs :: IO (IOArray Int a)
  getElems arr

I?ve got this error:

Could not deduce (a ~ a1)
from the context (Ord a)
  bound by the type signature for toHeap :: Ord a => [a] -> IO [a]
  at 
/var/folders/fk/339860r16j759wmsfmjkyr4h0000gn/T/flycheck797T5s/Heapsort.hs:9:11-32
  ?a? is a rigid type variable bound by
      the type signature for toHeap :: Ord a => [a] -> IO [a]
      at 
/var/folders/fk/339860r16j759wmsfmjkyr4h0000gn/T/flycheck797T5s/Heapsort.hs:9:11
  ?a1? is a rigid type variable bound by
       an expression type signature: IO (IOArray Int a1)
       at 
/var/folders/fk/339860r16j759wmsfmjkyr4h0000gn/T/flycheck797T5s/Heapsort.hs:14:10
Expected type: [a1]
  Actual type: [a]
Relevant bindings include
  xs :: [a]
    (bound at 
/var/folders/fk/339860r16j759wmsfmjkyr4h0000gn/T/flycheck797T5s/Heapsort.hs:12:8)
  toHeap :: [a] -> IO [a]
    (bound at 
/var/folders/fk/339860r16j759wmsfmjkyr4h0000gn/T/flycheck797T5s/Heapsort.hs:10:1)
In the second argument of ?newListArray?, namely ?xs?
In a stmt of a 'do' block:
  arr <- newListArray (1, length xs) xs :: IO (IOArray Int a)


But with the code below, all work:

toHeap :: Ord a => [a] -> IO [a]
toHeap [] = return []
toHeap [x] = return [x]
toHeap xs = do
  arr <- buildArray xs
  getElems arr


buildArray :: [a] -> IO (IOArray Int a)
buildArray xs = newListArray (1, length xs) xs

What do I miss ?

Thanks.

Chris

-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20150412/a79ca0e6/attachment-0001.html>

------------------------------

Message: 3
Date: Sun, 12 Apr 2015 12:55:05 -0400
From: Brandon Allbery <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Type declaration
Message-ID:
        <CAKFCL4V+pFSg_Pi-zyqqwKL6oGJ2MGULx6a8LxMz4j=+t6b...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

On Sun, Apr 12, 2015 at 12:41 PM, Christian Sperandio <
[email protected]> wrote:

> I?m currently playing with the mutable array to implement an heap sort
> sort (from The Art of Computer Programming) and I?m puzzled with an error.
>
> When I code:
>
> toHeap :: Ord a => [a] -> IO [a]
> toHeap [] = return []
> toHeap [x] = return [x]
> toHeap xs = do
>   arr <- newListArray (1, length xs) xs :: IO (IOArray Int a)
>   getElems arr
>

Note that the "a" in the signature "IO (IOArray Int a)" is *not* the same
as the one in the signature of toHeap; the scope of that type variable is
the signature itself, not the following equation(s). You have in effect
done the opposite of what you intended --- instead of asserting it is the
same, you asserted that it is a *different* one, by handing the compiler an
unexpected `a` which must be assumed to represent a distinct type.

If you need to extend the scope of a type variable like this, you need the
ScopedTypeVariables extension, and to declare the type variable as having
extended scope with an explicit `forall`:

{-# LANGUAGE ScopedTypeVariables #-}

toHeap :: forall a. Ord a => [a] -> IO [a]
toHeap [] = return []
toHeap [x] = return [x]
toHeap xs = do
  arr <- newListArray (1, length xs) xs :: IO (IOArray Int a)
  getElems arr

-- 
brandon s allbery kf8nh                               sine nomine associates
[email protected]                                  [email protected]
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20150412/ff6a145f/attachment-0001.html>

------------------------------

Message: 4
Date: Mon, 13 Apr 2015 14:56:47 +0800 (CST)
From: m00nlight <[email protected]>
To: "The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell" <[email protected]>
Subject: [Haskell-beginners] Operator orders affect parse result
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"

 Dear Haskellers,

I have tried the "while language parser" tutorial on haskellwiki, but I 
encounter an problem I can not understand here,
The following is the code:

http://pastebin.com/saC9vwCn


The problem is, with the code, the parse result of "fact := a / b * c" is
*Main> parseString "fact := a / b * c"
Assign "fact" (ABinary Multiply (ABinary Divide (Var "a") (Var "b")) (Var "c"))
*Main>

But if I swap the order of "/" and "*" operators in aOperators(make "*" appear 
before "/" operator),  then the result is
*Main> parseString "fact := a / b * c"
Assign "fact" (ABinary Divide (Var "a") (ABinary Multiply (Var "b") (Var "c")))
*Main>

So it seems that the order of the operator will affect the parse result. What's 
the problem with my code?  How can I
make my program to produce consistent parse result.

Best Regards,



--m00nlight


-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20150413/44c39ec7/attachment-0001.html>

------------------------------

Message: 5
Date: Mon, 13 Apr 2015 09:21:19 +0200
From: Francesco Ariis <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Operator orders affect parse result
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

On Mon, Apr 13, 2015 at 02:56:47PM +0800, m00nlight wrote:
>  Dear Haskellers,
> 
> I have tried the "while language parser" tutorial on haskellwiki, but I
> encounter an problem I can not understand here,
> The following is the code:
> 
> http://pastebin.com/saC9vwCn
> 
> 
> So it seems that the order of the operator will affect the parse result.
> What's the problem with my code?  How can I make my program to produce
> consistent parse result.

Checking the documentation for OperatorTable [1] (the first argument to
buildExpressionParser), it seems it is working as expected:

    An OperatorTable s u m a is a list of Operator s u m a lists. The list
    is ordered in descending precedence. All operators in one list have
    the same precedence (but may have a different associativity).

I think you can take advantage of the fact that OperatorTable is /a list
of lists/, hence

    aOperators = [ [Prefix (reservedOp "-" >> return (Neg ))]
                 , [Infix (reservedOp "/" >> return (ABinary Divide )) 
AssocLeft,
                    Infix (reservedOp "*" >> return (ABinary Multiply )) 
AssocLeft]
                 , [Infix (reservedOp "+" >> return (ABinary Add )) AssocLeft]
                 , [Infix (reservedOp "-" >> return (ABinary Subtract )) 
AssocLeft]
                 ]

should do the trick (try swapping the elements in the second list.
Will this do?


[1] 
http://hackage.haskell.org/package/parsec-3.0.0/docs/Text-Parsec-Expr.html#t:OperatorTable


------------------------------

Subject: Digest Footer

_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


------------------------------

End of Beginners Digest, Vol 82, Issue 12
*****************************************

Reply via email to