Send Beginners mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.haskell.org/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.  ghc problem (jean verdier)
   2. Re:  Re: Simplifying code (Daniel Fischer)
   3.  Re: Simplifying code (edgar klerks)
   4.  Is there a an include statement equivalence in   Haskell
      (Andrew Smith)
   5. Re:  Is there a an include statement equivalence  in Haskell
      (Colin Paul Adams)
   6. Re:  Is there a an include statement equivalence  in Haskell
      (Krzysztof Skrz?tnicki)
   7. Re:  Is there a an include statement equivalence  in Haskell
      (Stephen Tetley)
   8.  Re: Simplifying code (edgar klerks)
   9. Re:  Simplifying code (edgar klerks)


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

Message: 1
Date: Wed, 10 Feb 2010 10:52:24 +0100
From: jean verdier <[email protected]>
Subject: [Haskell-beginners] ghc problem
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain

Trying to compile sources gives me:

ghc: internal error: evacuate(static): strange closure type 34
    (GHC version 6.10.4 for i386_unknown_linux)
    Please report this as a GHC bug:
http://www.haskell.org/ghc/reportabug

This already occured to me some times before and a cleanup and recompile
would work. This time i am stuck as i can't compile anymore. The ghc
version i use is the 6.10.4 from the ghc home page binary distribution i
think.

uname -a gives :
Linux localhost.localdomain 2.6.29.4-167.fc11.i586 #1 SMP Wed May 27
17:14:37 EDT 2009 i686 athlon i386 GNU/Linux

The command line is:
ghc  -fwarn-incomplete-patterns -fno-warn-unused-binds
-fno-warn-unused-matches -fno-warn-unused-imports
-fno-warn-missing-signatures -fno-glasgow-exts -Werror
-outputdir /tmp/mfk/build -package ghc  -i/tmp/mfk/gensrc --make
common/MFK/Common/SrcGen.hs common/MFK/Common/Conf.hs 

Any hints ?



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

Message: 2
Date: Wed, 10 Feb 2010 11:27:11 +0100
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] Re: Simplifying code
To: [email protected]
Cc: edgar klerks <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain;  charset="utf-8"

Am Mittwoch 10 Februar 2010 05:49:46 schrieb edgar klerks:
> Hello all,
>
> I have a very interesting alternative solution of the problem. First I
> generate a tree with all the permutations:
>
> eg if I want to find al permutations of ao, I get the following tree
>
>    [a   @]
>
>   [o 0] [o 0]
>
> Then I walk trough the tree so I can print it. There is only one ugly
> thing. Showtree' returns a string (in our example a...@o@0). To make it
> a list i put a \n between a left and right node and then use lines to
> make it a list of strings. Can someone point me in the right direction
> how to beautify it a bit?
>
> I also have an annoying problem with gmail and firefox. It seems it
> doesn add my posts to the current thread, but starts a new one. Oh well
> think I switch to evolution.

Apparently, it doesn't set the in-reply-to field. That should be 
configurable.

> I will review all yours solutions tomorrow. I saw some very beautifull 
things.
>
> With kind regards,
>
> Edgar Klerks
>
> module Main where
> import Data.Char
>
> data WordTree = Chain (Char,WordTree)

Why add the extra tuple?
Better: Chain Char WordTree

>
>         |   Choice (Char, WordTree) (Char, WordTree)

Again, the tuples aren't necessary.

>         |   Stop
>
> instance Show WordTree where
>         show = unlines.showTree
>
> type Rule = (Char, Char)

I think it would be better to have

type Rule = (Char,[Char])

or even

data Rule a = Sub a [a]

or use a Map a [a].

You gain more flexibility that way and can use the same code if you can 
replace a Char (or whatever) with one of any number of possibilities.

The WordTree type would then become

data WordTree
    = Branch [(Char, WordTree)]
    | Tip

type Rules = Map Char [Char]

rules :: Rules
rules = fromList [('a',['a','@']),('l',['l','|'])]

subs :: Char -> Rules -> [Char]
subs c rs = findWithDefault [c] c rs

buildTree :: String -> Rules -> WordTree
buildTree (c:cs) rs 
    = let st = buildTree cs rs
      in Branch [(s,st) | s <- subs c rs]
buildTree "" _ = Tip

showTree (Branch ts) = [c:xs | (c,st) <- ts, xs <- showTree st]
showTree Tip = [""]

> type Rules = [Rule]
>
> infixl 4 ==>
>
> a ==> b = (a,b)
>
> rules :: Rules
> rules = [ 'a' ==> '@', 'l' ==> '|']
>
>
> buildTree :: String -> Rules -> WordTree
> buildTree [] r = Stop
> buildTree (c:cs) r = case lookup c r of
>                         Just a -> Choice (a, buildTree cs r) (c,
> buildTree cs r)

Share the subtree,
                        Just a -> let st = buildTree cs r
                                  in Choice (a,st) (c,st)

>                         Nothing -> Chain (c, buildTree cs r)
>
>
> showTree a = lines $ showTree' a []
>
> showTree' (Chain (a,b)) p  = a : showTree' b p
> showTree' (Choice (a,b) (c,d)) p  = c : showTree' d p ++ "\n" ++ (a :
> showTree' b p)
> showTree' (Stop) p   = p

showTree :: WordTree -> [String]
showTree (Chain (a,b)) = [a:xs | xs <- showTree b]
showTree (Choice (a,b) (c,d)) 
    = [a:xs | xs <- showTree b] ++ [c:ys | ys <- showTree d] 
showTree Stop = [""]



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

Message: 3
Date: Wed, 10 Feb 2010 11:47:09 +0100
From: edgar klerks <[email protected]>
Subject: [Haskell-beginners] Re: Simplifying code
To: [email protected], [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"

He Daniel.


I have some trouble understanding what you are saying here:

>* -- first I need to find  the positions of the mutatable charachters.
*
No, you don't need to do that, it's in general more efficient to not care
about positions when dealing with lists.

>* findPositions :: [Char] -> [[Int]]
*>* findPositions xs = take (length index) $ index <*> [xs]
*>*         where index = elemIndices <$> leata
*
[f1, ..., fm] <*> [x1, ..., xn]

produces a list of length m*n, so

length (index <*> [xs]) == length index * length [xs] == length index

~> remove "take (length index) $"

About this piece of code:


fmap snd <$> fmap unzip <$> p

Prelude Control.Applicative> let p = [[[(1,2),(3,4),(4,5)]]]
Prelude Control.Applicative> fmap snd <$> fmap unzip <$> p
[[[2,4,5]]]
Prelude Control.Applicative>

But yeah, it is ridiculously complicated. And I made it up by trial
and error and looking at the types.

I have a better approach now. I am now building a tree and then walk
trough it to collect all the permutations.

Thanks for your help and effort!


Edgar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://www.haskell.org/pipermail/beginners/attachments/20100210/9b5e40f8/attachment-0001.html

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

Message: 4
Date: Wed, 10 Feb 2010 11:17:06 +0000
From: Andrew Smith <[email protected]>
Subject: [Haskell-beginners] Is there a an include statement
        equivalence in  Haskell
To: [email protected]
Message-ID: <1265800626.9150.27.ca...@amd64-ws1>
Content-Type: text/plain; charset="UTF-8"

Hi
I have a few lines of Haskell which I'd like to be pulled into my
Haskell program, similar to the #include in C/C++, or Latex.

I don't want to just paste the code permanently using editor,  or pass
it through say M4, nor build my own module.

At the moment its a couple of lines I've used in three or four similar
programs.

As a Haskell beginner, is my thinking still stuck in the imperative
coding style era ?

-- 
Andrew



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

Message: 5
Date: Wed, 10 Feb 2010 11:23:43 +0000
From: Colin Paul Adams <[email protected]>
Subject: Re: [Haskell-beginners] Is there a an include statement
        equivalence     in Haskell
To: [email protected]
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

>>>>> "Andrew" == Andrew Smith <[email protected]> writes:

    Andrew> Hi I have a few lines of Haskell which I'd like to be pulled
    Andrew> into my Haskell program, similar to the #include in C/C++,
    Andrew> or Latex.

    Andrew> I don't want to just paste the code permanently using
    Andrew> editor, or pass it through say M4, nor build my own module.

    Andrew> At the moment its a couple of lines I've used in three or
    Andrew> four similar programs.

    Andrew> As a Haskell beginner, is my thinking still stuck in the
    Andrew> imperative coding style era ?

The equivalent is import.

Modules are lightweight. As are functions.
-- 
Colin Adams
Preston Lancashire


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

Message: 6
Date: Wed, 10 Feb 2010 12:27:39 +0100
From: Krzysztof Skrz?tnicki <[email protected]>
Subject: Re: [Haskell-beginners] Is there a an include statement
        equivalence     in Haskell
To: [email protected]
Cc: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=UTF-8

Hi

It's generally bad idea to include source code in this manner. It is
error prone, hard to understand and ugly. It's really better to use
modules instead.

But if you *really* want to rely on such hacks, then yes, it's
possible. Simply use cpp's #include. But first you need to enable CPP
extension. One way of doing it is writing this line as the first line:
> {-# LANGUAGE CPP #-}

With cpp in game you can then write:
> #include "common.hs"

Best regards
Krzysztof Skrzętnicki

On Wed, Feb 10, 2010 at 12:17, Andrew Smith <[email protected]> wrote:
> Hi
> I have a few lines of Haskell which I'd like to be pulled into my
> Haskell program, similar to the #include in C/C++, or Latex.
>
> I don't want to just paste the code permanently using editor,  or pass
> it through say M4, nor build my own module.
>
> At the moment its a couple of lines I've used in three or four similar
> programs.
>
> As a Haskell beginner, is my thinking still stuck in the imperative
> coding style era ?
>
> --
> Andrew
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>


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

Message: 7
Date: Wed, 10 Feb 2010 11:28:22 +0000
From: Stephen Tetley <[email protected]>
Subject: Re: [Haskell-beginners] Is there a an include statement
        equivalence     in Haskell
Cc: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

Hello Andrew

Do the few lines define Haskell expressions (functions or constants)
or are they something like a copyright notice (which you want the same
in all files)?

If they are functions, avoiding putting them in a module would seem a
bit dubious. Most people probably have their own collection of
'missing' functions from the Prelude that they share between their
projects, (of course everyone has different variations of 'missing'
functions...)

Best wishes

Stephen


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

Message: 8
Date: Wed, 10 Feb 2010 12:31:22 +0100
From: edgar klerks <[email protected]>
Subject: [Haskell-beginners] Re: Simplifying code
To: [email protected]
Message-ID: <1265801482.3408.14.ca...@edgar-desktop>
Content-Type: text/plain; charset="UTF-8"

>Why add the extra tuple?
>Better: Chain Char WordTree

It feels a bit too loose. Think it is a imperative quirk. I remove the tupples.


And I am going to change the type Rule to a Map. I have used that package 
before and it is fast
and easy to use. 

Another question. I have a book Real World Haskell, which is great, but I would 
like to read somewhat more indepth
stuff. Can you recommend one?

Thanks for your advice.

With kind regards,

Edgar

I switched to evolution. Hopefully it will take the in reply to field.



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

Message: 9
Date: Wed, 10 Feb 2010 12:48:07 +0100
From: edgar klerks <[email protected]>
Subject: Re: [Haskell-beginners] Simplifying code
To: Patrick LeBoutillier <[email protected]>
Cc: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"

I found out I get the posts in my mail and I am clicking in the mailinglist.
Therefore I am starting new threads over and over again. My apologies.

>Why add the extra tuple?
>Better: Chain Char WordTree

It feels a bit too loose. Think it is a imperative quirk. I remove the
tupples.


And I am going to change the type Rule to a Map. I have used that package
before and it is fast
and easy to use.

Another question. I have a book Real World Haskell, which is great, but I
would like to read somewhat more indepth
stuff. Can you recommend one?

Thanks for your advice.

With kind regards,

Edgar

I switched to evolution. Hopefully it will take the in reply to field.

On Tue, Feb 9, 2010 at 11:07 PM, Patrick LeBoutillier <
[email protected]> wrote:

> Daniel,
>
> > Sure. If you don't mind that the mutations come in a different order, one
> > thing that works wonders is "sequence",
> >
> > sequence :: Monad m => [m a] -> m [a]
> >
> > In particular, for m = [], sequence :: [[a]] -> [[a]]. Then, knowing what
> > sequence does, we can write
> >
> > import Control.Monad (sequence)
> >
> > generateAll :: String -> [String]
> > generateAll word = sequence (map f word)
> >     where
> >     f c = case lookup c leat of
> >                Just r  -> [c,r]
> >                Nothing -> [c]
>
> That's very nice!
>
> One question though: In the docs sequence is described as:
>
>  "Evaluate each action in the sequence from left to right, and
> collect the results."
>
> How is one supposed to deduce what the behavior will be for the list
> monad (besides looking at the source)?
>
>
> Patrick
>
> --
> =====================
> Patrick LeBoutillier
> Rosemère, Québec, Canada
>



-- 
Flatliner ICT Service,
Email: [email protected],
Tel: +31727851429
Fax: +31848363080
Skype: edgar.klerks
Website: flatlinerict.nl
Adres: Koelmalaan 258,
1813JD, Alkmaar
Nederland
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://www.haskell.org/pipermail/beginners/attachments/20100210/816852b9/attachment.html

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

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 20, Issue 18
*****************************************

Reply via email to