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. Re: Re: Simplifying code (edgar klerks)
2. Re: Re: Simplifying code (edgar klerks)
3. HackageDB - How to browse by development status (Gabi)
4. let expression (John Moore)
5. Re: let expression (Stephen Tetley)
----------------------------------------------------------------------
Message: 1
Date: Wed, 10 Feb 2010 13:47:58 +0100
From: edgar klerks <[email protected]>
Subject: Re: [Haskell-beginners] Re: Simplifying code
To: Daniel Fischer <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
He Daniel,
I use the Data.Map now, this makes it way more flexibler
data WordTree
> = Branch [(Char, WordTree)]
> | Tip
>
>
I only don't use this type of Tree. I am not sure how it works, but it looks
good, so I will experiment with it. Is it a so called rose tree? (Then I can
find some articles about it).
>
> Share the subtree,
> Just a -> let st = buildTree cs r
> in Choice (a,st) (c,st)
>
> Stupid thing not to do, think I overlooked it :)
Thanks again.
Edgar
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20100210/d96a73d6/attachment-0001.html
------------------------------
Message: 2
Date: Wed, 10 Feb 2010 14:31:56 +0100
From: edgar klerks <[email protected]>
Subject: Re: [Haskell-beginners] Re: Simplifying code
To: Daniel Fischer <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
He Daniel,
I used your showTree function because it works better than mine. I also
think the program is now truly functional. I will try to implement the other
tree on my own to see how it goes.
It now looks like this:
module Main where
import Data.Char
import System
import qualified Data.Map as M
import Control.Applicative ((<$>))
--- CONFIG SECTION ---
-- add the characters you want to permutate here--
rules :: Rules
rules = M.fromList [
'a' ==> "@",
'l' ==> "|",
'w' ==> "\\|/",
'v' ==> "\\/",
'o' ==> "0"]
data WordTree = Chain String WordTree
| Choice String WordTree String WordTree
| Stop
deriving Show
--instance Show WordTree where
-- show = unlines.showTree
type Rules = M.Map Char [Char]
infixl 4 ==>
(==>) :: a -> b -> (a, b)
a ==> b = (a, b)
buildTree :: String -> Rules -> WordTree
buildTree [] r = Stop
buildTree (c:cs) r = case M.lookup c r of
Just a -> let p = buildTree cs r
in Choice a p [c] p
Nothing -> Chain [c] $ buildTree cs r
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 = [""]
main :: IO ()
main = do
filename <- head <$> getArgs
wordlist <- readFile $ filename
let a = (flip buildTree $ rules) <$> (lines wordlist) >>= showTree
mapM_ putStrLn a
~
On Wed, Feb 10, 2010 at 1:47 PM, edgar klerks <[email protected]>wrote:
> He Daniel,
>
> I use the Data.Map now, this makes it way more flexibler
>
>
> data WordTree
>> = Branch [(Char, WordTree)]
>> | Tip
>>
>>
> I only don't use this type of Tree. I am not sure how it works, but it
> looks good, so I will experiment with it. Is it a so called rose tree? (Then
> I can find some articles about it).
>
>
>>
>> Share the subtree,
>> Just a -> let st = buildTree cs r
>> in Choice (a,st) (c,st)
>>
>> Stupid thing not to do, think I overlooked it :)
>
> Thanks again.
>
> Edgar
>
--
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/964f8830/attachment-0001.html
------------------------------
Message: 3
Date: Wed, 10 Feb 2010 20:44:11 +0200
From: Gabi <[email protected]>
Subject: [Haskell-beginners] HackageDB - How to browse by development
status
To: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
Hi
I really miss the option browsing this big DB by development status
(.e.g. alpha,beta,stable,mature,inactive)
It is very common (in other langs at least) to have some approx
development status.
Otherwise it is really hard to choose. How can I know if a package is
considered stable enough for production ?
--
Regards,
Gabi
http://bugspy.net
------------------------------
Message: 4
Date: Wed, 10 Feb 2010 20:16:31 +0000
From: John Moore <[email protected]>
Subject: [Haskell-beginners] let expression
To: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Hi All,
Trying to get this to work, keeps telling me there a parse error on
right in the let expression. Can anyone see where the problem is and be able
to explain it to me.
import Maybe
data Expression = Val Double
| Add Expression Expression
| Subtract Expression Expression
| Multiply Expression Expression
| Divide Expression Expression
| Var String
| Let String Expression Expression
deriving Show
demo1 = (Add(Multiply(Divide(Subtract(Val 25)(Val 5))(Val 10))(Val 7))(Val
30))
type Dict =[(String,Expression)]
emptyDict :: Dict
emptyDict = []
addEntry :: String->Expression ->Dict -> Dict
addEntry n e d = (n,e): d
lookupEntry :: String -> Dict -> Maybe Expression
lookupEntry n [] = Nothing
lookupEntry n (x:xs) = if (n == k)
then (Just v)
else lookupEntry n xs
where (k,v) = x
evalStep :: Dict -> Expression -> Expression
evalStep d(Val x)= (Val x)
evalStep d(Add x y)
= case x of
(Val a) -> case y of
(Val b) -> Val (a+b)
left -> Add x (evalStep d y)
right -> Add (evalStep d x)y
evalStep d(Subtract x y)
= case x of
(Val a) -> case y of
(Val b) -> Val (a-b)
left -> Subtract x (evalStep d y)
right -> Subtract (evalStep d x)y
evalStep d(Multiply x y)
= case x of
(Val a) -> case y of
(Val b) -> Val (a*b)
left -> Multiply x (evalStep d y)
right -> Multiply (evalStep d x)y
evalStep d (Divide x y)
= case x of
(Val a) -> case y of
(Val b) -> Val (a/b)
left -> Divide x (evalStep d y)
right -> Divide (evalStep d x)y
evalStep d (Let n e1 e2)
= case e1 of
(Val a) -> case e2 of
(Val b)-> Val (Let e1 e2)
left -> Let e1 (evalStep d e2)
right -> Let (evalStep d e1) e2
evaluate :: Dict-> [Expression] -> Expression -> IO()
evaluate d(x:xs) e = do
putStrLn (show e)
putStrLn "Do another step (y/n) or rollback (r)? :"
c <- getLine
case c of
"y" -> let e'= (evalStep d e)in evaluate d (e:x:xs) e'-- build up
history
"r" -> case (x:xs) of
(x:xs)-> evaluate d xs x
[]-> do { putStrLn "Empty"
;evaluate d(x:xs) e
}
"n" -> putStrLn $ "Ok you said no :" ++ c
John
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20100210/512a91cc/attachment-0001.html
------------------------------
Message: 5
Date: Wed, 10 Feb 2010 20:26:34 +0000
From: Stephen Tetley <[email protected]>
Subject: Re: [Haskell-beginners] let expression
To: John Moore <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
Hi John
Provided the whitespace doesn't get mangled in the mail the last
evalStep needs indenting correctly:
evalStep d (Let n e1 e2)
= case e1 of
(Val a) -> case e2 of
(Val b)-> Val (Let e1 e2)
left -> Let e1 (evalStep d e2)
right -> Let (evalStep d e1) e2
Also the "r" case in evaluate:
"r" -> case (x:xs) of
(x:xs) -> evaluate d xs x
[] -> do { putStrLn "Empty"
;evaluate d(x:xs) e
}
You might want to consider using wildcards (i.e. underscores) _ rather
than variables e.g 'left' and 'right' when you don't use the value of
a pattern match at the right of the "->".
Best wishes
Stephen
On 10 February 2010 20:16, John Moore <[email protected]> wrote:
> Hi All,
> Trying to get this to work, keeps telling me there a parse error on
> right in the let expression. Can anyone see where the problem is and be able
> to explain it to me.
>
> import Maybe
> data Expression = Val Double
> | Add Expression Expression
> | Subtract Expression Expression
> | Multiply Expression Expression
> | Divide Expression Expression
> | Var String
> | Let String Expression Expression
> deriving Show
> demo1 = (Add(Multiply(Divide(Subtract(Val 25)(Val 5))(Val 10))(Val 7))(Val
> 30))
> type Dict =[(String,Expression)]
> emptyDict :: Dict
> emptyDict = []
> addEntry :: String->Expression ->Dict -> Dict
> addEntry n e d = (n,e): d
> lookupEntry :: String -> Dict -> Maybe Expression
> lookupEntry n [] = Nothing
> lookupEntry n (x:xs) = if (n == k)
> then (Just v)
> else lookupEntry n xs
> where (k,v) = x
> evalStep :: Dict -> Expression -> Expression
> evalStep d(Val x)= (Val x)
> evalStep d(Add x y)
> = case x of
> (Val a) -> case y of
> (Val b) -> Val (a+b)
> left -> Add x (evalStep d y)
> right -> Add (evalStep d x)y
> evalStep d(Subtract x y)
> = case x of
> (Val a) -> case y of
> (Val b) -> Val (a-b)
> left -> Subtract x (evalStep d y)
> right -> Subtract (evalStep d x)y
> evalStep d(Multiply x y)
> = case x of
> (Val a) -> case y of
> (Val b) -> Val (a*b)
> left -> Multiply x (evalStep d y)
> right -> Multiply (evalStep d x)y
> evalStep d (Divide x y)
> = case x of
> (Val a) -> case y of
> (Val b) -> Val (a/b)
> left -> Divide x (evalStep d y)
> right -> Divide (evalStep d x)y
> evalStep d (Let n e1 e2)
> = case e1 of
> (Val a) -> case e2 of
> (Val b)-> Val (Let e1 e2)
> left -> Let e1 (evalStep d e2)
> right -> Let (evalStep d e1) e2
>
>
> evaluate :: Dict-> [Expression] -> Expression -> IO()
> evaluate d(x:xs) e = do
> putStrLn (show e)
> putStrLn "Do another step (y/n) or rollback (r)? :"
> c <- getLine
> case c of
> "y" -> let e'= (evalStep d e)in evaluate d (e:x:xs) e'-- build up
> history
>
> "r" -> case (x:xs) of
> (x:xs)-> evaluate d xs x
> []-> do { putStrLn "Empty"
> ;evaluate d(x:xs) e
> }
> "n" -> putStrLn $ "Ok you said no :" ++ c
>
>
> John
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 20, Issue 19
*****************************************