Russ Abbott | 1 Jul 06:17 2016
Picon
Gravatar

Problem with installing GHCi 8.0.1

I downloaded GHCi 8.0.1 for Windows. Since I don't have administrator privileges I repeatedly clicked no when asked if I wanted to stop and restart with elevated privileges. Eventually it installed (in a folder on the desktop). The next step tells me to change some lines in the cabal user-config file.  I followed the instructions to find that file, but all I got was an html file, which didn't seem right.  I looked manually in multiple directories, but nothing seemed like the right file. Would someone help me find the file that needs to be changed.

Also, WinGHCi does not appear in my start menu. Should it appear there by this point?

Thanks.
_______________________________________________
Beginners mailing list
Beginners <at> haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Dennis Raddle | 29 Jun 10:20 2016
Picon

error writing FilePath to text file

Hello, I wrote a program that reads filenames using System.Directory "listDirectory", does some tests on them, and writes certain file names (as read into a FilePath variable by listDirectory) to a text file, which I later parse with Parsec.  I am getting an error on writing to the text file:

commitBuffer: invalid argument (invalid character)

What can I do about this? If I am reading some kind of unusual characters from the FilePath, I want to choose some way of writing them so that the resulting file can still be parsed by Text.Parsec.ByteString. I hope that I can still rely on the "space" parser to find CR and LF, and don't want any other surprises. 

D

_______________________________________________
Beginners mailing list
Beginners <at> haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Desonte Jolivet | 29 Jun 05:39 2016
Picon

Generating Infinite List of Fibonacci Numbers


Hi,


Problem: I would like to generate an infinite list of Fibonacci numbers. Although the below code does not work.


fibs :: [Integer]
fibs = 0 : 1 : [ n | x <-[2..], let n = ((fibs !! x-1) + (fibs !! x-2))]


Thought: I'm assuming that I'm ignorant on how ranges/generators work with a list comprehension, which is why this code is not working.

ghci output:

*Main> fibs !! 0
1
*Main> fibs !! 1
2
*Main> fibs !! 2
 
When I try and access the third element in the list ghci simply stalls.

Can someone please give me a little more insight on why my code is not working.

Thanks in advance.

drjoliv

_______________________________________________
Beginners mailing list
Beginners <at> haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
martin | 28 Jun 20:39 2016
Picon

RDBMS like references?

Hello all,

I recently tried to model "Items", where an Item can either be inside another Item or at a certain location. I started
like this:

data Location i l = At l
                  | In (Item i l)
                    deriving (Eq, Show)

data Item i l     = Itm i (Location i l)
                    deriving (Eq, Show)

type ItemDb i l = [Item i l]

ex_itemdb = let i1 = Itm 1 (At "a")
                i2 = Itm 2 (In i1)
            in [i1, i2]

Now I wanted to move Item 1 to a different location using this code:

moved = fmap f ex_itemdb
        where
            f (Itm 1 (At "a")) = (Itm 1 (At "b"))
            f x = x

Not this does not do what I want. I get

-- *Main> ex_itemdb
-- [Itm 1 (At "a"),Itm 2 (In (Itm 1 (At "a")))]

-- *Main> moved
-- [Itm 1 (At "b"),Itm 2 (In (Itm 1 (At "a")))]

While Item 1 has moved to "b" Item 2 still claims to be in an "Itm 1 (At "a")". I understand what's going on here and
coming from a DB background I can see that the redundant data is the root of the problem.

I can model this in a relational way such that the redundancy is avoided. But maybe there is a more haskellish/idiomatic
way to acomplish this.

Is there?

_______________________________________________
Beginners mailing list
Beginners <at> haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
PICCA Frederic-Emmanuel | 27 Jun 18:49 2016
Picon

Strorable and incomplete type

Hello,

I would like to use Storable and declare an instance for a struct available in a C library

instance Storable Parameter where
    sizeOf _ = #{size HklParameter}
    peek ptr = alloca $ \pmin ->
               alloca $ \pmax -> do
                              cname <- c_hkl_parameter_name_get ptr
                              name <- peekCString cname
                              value <- c_hkl_parameter_value_get ptr unit
                              c_hkl_parameter_min_max_get ptr pmin pmax unit
                              min <- peek pmin
                              max <- peek pmax
                              return (Parameter name value (Range min max))

but when I try to compile this, I get this error message

C.hsc:507:15: error: invalid application of ‘sizeof’ to incomplete type ‘HklParameter’

Indeed the C library do not expose this struct internal.

So I would like to know how to handle this kind of C struct with Storable.

thanks for your help

Frédéric
_______________________________________________
Beginners mailing list
Beginners <at> haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Timothy Washington | 23 Jun 09:58 2016
Picon

Howto reverse a Data.Array

I'm still trying to get an intuitive understanding of Haskell's Data.Array, in contrast to Data.List or Data.Vector. 

I very much want a nested array (a matrix), where the parent list (or rows) are reversed. But neither A.array nor A.istArray allow indicies to be reversed in their constructors, nor the list comprehensions that generate the elements 

The only reason I'm using an array, is for the A.// function (operating on a matrix). Otherwise, I'd use Data.Vector which does have a reverse function, but a less powerful V.// , that doesn't accept coordinates in a matrix.

Can I reverse a Data.Array? If not, then why. 


Thanks 
Tim 

_______________________________________________
Beginners mailing list
Beginners <at> haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Graham Hutton | 21 Jun 16:05 2016
Picon
Picon

Programming in Haskell - 2nd Edition

Dear all,

I'm delighted to announce that the 2nd edition of Programming
in Haskell will be published in August 2016!  The new edition
has been extensively updated and expanded to include recent and
more advanced features of Haskell, new examples and exercises,
selected solutions, and freely downloadable lecture slides and
example code.  Further details, including how to preorder and
obtain inspection copies, are provided below.

Best wishes,

Graham

=================================================================

*** BOOK ANNOUNCEMENT ***

Programming in Haskell - 2nd Edition

Graham Hutton, University of Nottingham

Cambridge University Press, August 2016

320 pages, 120 exercises, ISBN 9781316626221

http://tinyurl.com/PIH-2e

=================================================================

DESCRIPTION:

Haskell is a purely functional language that allows programmers
to rapidly develop clear, concise, and correct software.  The
language has grown in popularity in recent years, both in teaching
and in industry.  This book is based on the author's experience
of teaching Haskell for more than twenty years.  All concepts
are explained from first principles and no programming experience
is required, making this book accessible to a broad spectrum
of readers.  While Part I focuses on basic concepts, Part II
introduces the reader to more advanced topics.

This new edition has been extensively updated and expanded to
include recent and more advanced features of Haskell, new examples
and exercises, selected solutions, and freely downloadable lecture
slides and example code.  The presentation is clean and simple,
while also being fully compliant with the latest version of
the language, including recent changes concerning applicative,
monadic, foldable, and traversable types.

=================================================================

CONTENTS:

Foreword
Preface
Part I. Basic Concepts:
1. Introduction
2. First steps
3. Types and classes
4. Defining functions
5. List comprehensions
6. Recursive functions
7. Higher-order functions
8. Declaring types and classes
9. The countdown problem
Part II. Going Further:
10. Interactive programming
11. Unbeatable tic-tac-toe
12. Monads and more
13. Monadic parsing
14. Foldables and friends
15. Lazy evaluation
16. Reasoning about programs
17. Calculating compilers
Appendix A. Selected solutions
Appendix B. Standard prelude
Bibliography
Index

=================================================================

AUTHOR:

Graham Hutton is Professor of Computer Science at the University
of Nottingham.  He has taught Haskell to thousands of students
and received numerous best lecturer awards.  Hutton has served as
an editor of the Journal of Functional Programming, Chair of the
Haskell Symposium and the International Conference on Functional
Programming, and Vice-Chair of the ACM Special Interest Group on
Programming Languages, and he is an ACM Distinguished Scientist.

=================================================================

FURTHER DETAILS:

The following web page includes details for how the book can be
preordered, and how lecturers can obtain inspection copies:

http://tinyurl.com/PIH-2e

=================================================================

This message and any attachment are intended solely for the addressee
and may contain confidential information. If you have received this
message in error, please send it back to me, and immediately delete it. 

Please do not use, copy or disclose the information contained in this
message or in any attachment.  Any views or opinions expressed by the
author of this email do not necessarily reflect the views of the
University of Nottingham.

This message has been checked for viruses but the contents of an
attachment may still contain software viruses which could damage your
computer system, you are advised to perform your own checks. Email
communications with the University of Nottingham may be monitored as
permitted by UK legislation.

_______________________________________________
Beginners mailing list
Beginners <at> haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Imants Cekusins | 16 Jun 10:04 2016
Picon

default(Int)

default(Int)

allows to use integers anywhere in this module without specifying their ambiguous type each time, like this: (3::Int)

section 10.4

some other default types may be specified too
somehow I was not aware of this
<div><div dir="ltr">
<div>default(Int)<br>
</div>
<div><br></div>
<div>allows to use integers anywhere in this module without specifying their ambiguous type each time, like this: (3::Int)</div>
<div><br></div>
<div>
<a href="https://www.haskell.org/tutorial/numbers.html">https://www.haskell.org/tutorial/numbers.html</a><br>
</div>
<div>section 10.4</div>
<div><br></div>
<div>some other default types may be specified too</div>
<div>somehow I was not aware of this</div>
</div></div>
martin | 12 Jun 23:11 2016
Picon

State Monad in constant space?

Hello all,

the State Monad wraps around a computation s -> (s,a). Inside a do block I am actually assembling such a computation.
Now when I do this many times, i.e. in a recursice call, I am builing a huge expression

	m a >>= (\a -> mb) >>= (\b -> mc) ...

The result of this expression is a function s -> (s,a). But I cannot see how the space for this expression can be
reclaimed, and how it could ever run in constant space. Once I call runState and I provide an initial s, I have some
hope, but before?

How is this supposed to work? How do I avoid allocating space for this huge expression?
martin | 12 Jun 15:38 2016
Picon

How to hunt this space-leak

Hello all,

I hope I am not asking for too much, as to explain my problem, you need to read my code, which may not be a pleasure.

I am trying to write a "Logger", which formats and accumulates log-entries in a monoid. From there I went to
writing an
"accumulating" logger, i.e. one which can accumulate (sum/avg) over entries made with a certain timespan.

My problen is memory consumption. In the test below I stress the logger with 1 million values, but in the end result,
there are only 10 entries left, because it accumulates over 100,000. Memory goes up to apx 100MB.

When I comment out the line, which logs the accumulated value (see -- > below), memory stays below 10MB. I dont
understand why this is so. After all, the difference is only whether or not those 10 entries are logged or not.

Can someone explain this?

{-# LANGUAGE BangPatterns#-}

import Data.Monoid
import Control.Monad.State.Strict
import System.TimeIt
import Text.Show.Pretty
import Debug.Trace

------------------------------------------------------------
-- Simple Time Stuff
------------------------------------------------------------
type Instant = Double
type Interval = Double
type Timed a = (Instant, a)
instant = fst

------------------------------------------------------------
-- Logger based on State monad
------------------------------------------------------------

data SLogger a l = SLgr {runSLogger :: a ->State l (SLogger a l)}
type SLogFormatter a l = a -> l

accLogger :: (Monoid c, Show a) =>
             (Instant, Interval, [Timed b]) ->
             SLogFormatter (Timed a) [Timed b] -> SLogFormatter [Timed b] [Timed c] ->  SLogger (Timed a) [Timed c]

accLogger (tx, dt, tas) fmt1 fmt2 = SLgr $ \(!ta) ->
                                    let x    = fmt1 ta
                                        !tas' = x <> tas
                                    in
                                        if instant ta < tx
                                        then do
                                            -- keep accumulating
                                            return $ accLogger (tx, dt, tas') fmt1 fmt2
                                        else do
                                            -- compute new log and reset accumulator
                                            !l0 <- get
-- >                                            put $ fmt2 tas'  <> l0
                                            return $ accLogger ((tx+dt), dt, []) fmt1 fmt2

accFmt1 ta = [ta]
accFmt2 tas = [(fst $ head tas, "hello from accFormatter")]

-- apply logger to a list of as
stest lgr [] = return lgr
stest lgr (a:as) = do
    lgr'  <-  (runSLogger lgr) a
    stest lgr' as

main2 = do
    let as = zip [1.0 .. 1000000.0] [1..1000000] :: [(Instant, Int)]
        log = execState (stest (accLogger (100000.0,100000.0,[]) accFmt1 accFmt2 ) as) [(0,"init")]
    timeIt $ putStrLn $ ppShow log
    putStrLn "done"

main = main2

Alex Belanger | 4 Jun 16:27 2016
Picon
Gravatar

Re: Functions as containers; implications on being a Monad ((->) r)

Does it help if I bring your:

(\x -> x+7) <$> (+3) => (+10)

It doesn't magically become `(+10)`. The previous step unseen is `(+7) . (+3)`. fmap for ((->) r) is defined as function  composition `.`.

fmap f g = f . g

You can think of functors as containers or contexts; both analogies work well up to some degree (with the latter maybe more abstract and thus flexible).

Another small terminology tip that could help you with your thinkering might be to call ((->) r) a partially applied function. Suddently, it narrows how you can potentially use/combine them.

Last tip, Monad ((->) r) is commonly refered to as the Reader monad. Example of how it'd be used:

doThings = do
    a <- (*2)
    b <- (+10)
    return (a + b)

Notice how we can work with partially applied functions to which something have yet to be applied and create a new partial function whose argument is going to fill all the open holes.

This isn't easy to explain without looking at the types of everything, so I encourage you to write it down and work out the types (:

Alex

On Jun 4, 2016 12:41 AM, "Raja" <rajasharan <at> gmail.com> wrote:

Everyone agrees ((->) r) is a Functor, an Applicative and a Monad but I've never seen any good writeup going into details of explaining this.

So I was trying to brainstorm with my brother and went pretty far into the concept for quite a few hours, but still got stuck when it came to Monads.

Before I showcase the question/problem I wanted to share our thinking process.

Lets stick with common types like Maybe a, [a], simple function (a -> b)

**Everything is a Container**

 Just 4 => this is a container wrapping some value
[1,2,3] => this is a container wrapping bunch of values
(+3) => this is a container wrapping domains & ranges (infinite dictionary)

**When is a Container a Functor**

If we can peek inside a container and apply a simple function (a->b) to each of its values and wrap the result back inside the container, then it becomes a Functor.

Let's use (\x -> x+7) as simple function along with above three Containers

(\x -> x+7) <$> Just 4 => Just 11
(\x -> x+7) <$> [1,2,3] => [8,9,10]
(\x -> x+7) <$> (+3) => (+10)  -- well there is no Show defined but you get the idea

**When is a Container an Applicative**

The simple function from above is also now wrapped inside a container and we should be able to peek to use it just like functor. Also lets simplify (\x -> x+7) to (+7).

Just (+7) <*> Just 4 => Just 11
[(+7)] <*> [1,2,3] => [8,9,10]
(\x -> (+7)) <*> (+3) => (+10) -- again no Show defined but works when pass a number
-- but (+7) still needs to be wrapped in a Container though

**When is a Container a Monad**

This time we don't have a simple function (a->b) instead we have a non-simple function (a -> Container). But rest stays almost the same. 

We have to first peek inside a container and apply non-simple function to each of its values. Since its a non-simple function we need to collect all the returned Containers, unwrap them and wrap them all back in a Container again. 
(it almost feels like unwrap and wrapping them back is going to complicate things)

Also Non-simple function cannot be reused as is for all three Containers like in Functors & Applicatives.

Just 4 >>= (\x -> Just (x+7)) => Just 11
[1,2,3] >>= (\x -> [x+7]) => [8,9,10]
(+3) >>= (\x -> (+7)) => (+7) 

Wait a minute ... the last line doesn't look right. Or should I say it doesn't feel right to discard the `x' altogether. 

OK let's jump to do this:
(+3) >>= (\x -> (+x)) => ??? -- apparently this solves for the equation: f(x) = 2x + 3

(is 2x + 3 obvious for anyone??? it took us way longer to derive it)
(Does it have anything to do with Monad laws by any chance?)

This is where it feels like "Functions as containers" concept starts to breakdown; its not the right analogy for Monads. 

What does it even mean to unwrap a bunch of functions and wrap them back again?

Hope this intrigues some of you as it did to us. Any thoughts and comments greatly appreciated.

Thanks,
Raja

_______________________________________________
Beginners mailing list
Beginners <at> haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

<div>
<p dir="ltr">Does it help if I bring your:</p>
<p dir="ltr">(\x -&gt; x+7) &lt;$&gt; (+3) =&gt; (+10)</p>
<p dir="ltr">It doesn't magically become `(+10)`. The previous step unseen is `(+7) . (+3)`. fmap for ((-&gt;) r) is defined as function&nbsp; composition `.`.</p>
<p dir="ltr">fmap f g = f . g</p>
<p dir="ltr">You can think of functors as containers or contexts; both analogies work well up to some degree (with the latter maybe more abstract and thus flexible).</p>
<p dir="ltr">Another small terminology tip that could help you with your thinkering might be to call ((-&gt;) r) a partially applied function. Suddently, it narrows how you can potentially use/combine them.</p>
<p dir="ltr">Last tip, Monad ((-&gt;) r) is commonly refered to as the Reader monad. Example of how it'd be used:</p>
<p dir="ltr">doThings = do<br>
&nbsp;&nbsp;&nbsp; a &lt;- (*2)<br>
&nbsp;&nbsp;&nbsp; b &lt;- (+10)<br>
&nbsp;&nbsp;&nbsp; return (a + b)</p>
<p dir="ltr">Notice how we can work with partially applied functions to which something have yet to be applied and create a new partial function whose argument is going to fill all the open holes.</p>
<p dir="ltr">This isn't easy to explain without looking at the types of everything, so I encourage you to write it down and work out the types (:</p>
<p dir="ltr">Alex</p>
<div class="gmail_quote">On Jun 4, 2016 12:41 AM, "Raja" &lt;<a href="mailto:rajasharan <at> gmail.com">rajasharan <at> gmail.com</a>&gt; wrote:<br type="attribution"><blockquote class="quote">
<div dir="ltr">
<div><br></div>
<div>Everyone agrees ((-&gt;) r) is a Functor, an Applicative and a Monad but I've never seen any good writeup going into details of explaining this.<br>
</div>
<div>
<br>So I was trying to brainstorm with my brother and went pretty far into the concept for quite a few hours, but still got stuck when it came to Monads.</div>
<div><br></div>
<div>Before I showcase the question/problem I wanted to share our thinking process.<br><br>Lets stick with common types like Maybe a, [a], simple function (a -&gt; b)</div>
<div><br></div>
<div>**Everything is a Container**≤/div>
<div>
<br>&nbsp;Just 4 =&gt; this is a container wrapping some value<br>[1,2,3] =&gt; this is a container wrapping bunch of values</div>
<div>(+3) =&gt; this is a container wrapping domains &amp; ranges (infinite dictionary)</div>
<div><br></div>
<div>**When is a Container a Functor**≤/div>
<div><br></div>
<div>If we can peek inside a container and apply a simple function (a-&gt;b) to each of its values and wrap the result back inside the container, then it becomes a Functor.</div>
<div><br></div>
<div>Let's use (\x -&gt; x+7) as simple function along with above three Containers</div>
<div><br></div>
<div>(\x -&gt; x+7) &lt;$&gt; Just 4 =&gt; Just 11</div>
<div>(\x -&gt; x+7) &lt;$&gt; [1,2,3] =&gt; [8,9,10]</div>
<div>(\x -&gt; x+7) &lt;$&gt; (+3) =&gt; (+10) &nbsp;-- well there is no Show defined but you get the idea</div>
<div><br></div>
<div>**When is a Container an Applicative**≤/div>
<div><br></div>
<div>The simple function from above is also now wrapped inside a container and we should be able to peek to use it just like functor. Also lets simplify (\x -&gt; x+7) to (+7).</div>
<div><br></div>
<div>Just (+7) &lt;*&gt; Just 4 =&gt; Just 11</div>
<div>[(+7)] &lt;*&gt; [1,2,3] =&gt; [8,9,10]</div>
<div>(\x -&gt; (+7)) &lt;*&gt; (+3) =&gt; (+10) -- again no Show defined but works when pass a number</div>
<div>-- but (+7) still needs to be wrapped in a Container though</div>
<div><br></div>
<div>**When is a Container a Monad**≤/div>
<div><br></div>
<div>This time we don't have a simple function (a-&gt;b) instead we have a non-simple function (a -&gt; Container). But rest stays almost the same.&nbsp;</div>
<div><br></div>
<div>We have to first peek inside a container and apply non-simple function to each of its values. Since its a non-simple function we need to collect all the returned Containers, unwrap them and wrap them all back in a Container again.&nbsp;</div>
<div>(it almost feels like unwrap and wrapping them back is going to complicate things)</div>
<div><br></div>
<div>Also Non-simple function cannot be reused as is for all three Containers like in Functors &amp; Applicatives.</div>
<div><br></div>
<div>Just 4 &gt;&gt;= (\x -&gt; Just (x+7)) =&gt; Just 11</div>
<div>[1,2,3] &gt;&gt;= (\x -&gt; [x+7]) =&gt; [8,9,10]</div>
<div>(+3) &gt;&gt;= (\x -&gt; (+7)) =&gt; (+7)&nbsp;</div>
<div><br></div>
<div>Wait a minute ... the last line doesn't look right. Or should I say it doesn't feel right to discard the `x' altogether.&nbsp;</div>
<div><br></div>
<div>OK let's jump to do this:</div>
<div>(+3) &gt;&gt;= (\x -&gt; (+x)) =&gt; ??? -- apparently this solves for the equation: f(x) = 2x + 3</div>
<div><br></div>
<div>(is 2x + 3 obvious for anyone??? it took us way longer to derive it)</div>
<div>(Does it have anything to do with Monad laws by any chance?)</div>
<div><br></div>
<div>This is where it feels like "Functions as containers" concept starts to breakdown; its not the right analogy for Monads.&nbsp;</div>
<div><br></div>
<div>What does it even mean to unwrap a bunch of functions and wrap them back again?</div>
<div><br></div>
<div>Hope this intrigues some of you as it did to us. Any thoughts and comments greatly appreciated.</div>
<div><br></div>
<div>Thanks,</div>
<div>Raja</div>
</div>
<br>_______________________________________________<br>
Beginners mailing list<br><a href="mailto:Beginners <at> haskell.org">Beginners <at> haskell.org</a><br><a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br><br>
</blockquote>
</div>
</div>

Gmane