SunQuest
           Other Programming Languages
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreOther Programming Languages

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old June 22nd, 2007, 03:16 AM
IOI-RLZ's Avatar
IOI-RLZ IOI-RLZ is offline
BANDITS 6'0 Clock !
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2006
Location: INDIYEAH !
Posts: 547 IOI-RLZ User rank is Captain (20000 - 30000 Reputation Level)IOI-RLZ User rank is Captain (20000 - 30000 Reputation Level)IOI-RLZ User rank is Captain (20000 - 30000 Reputation Level)IOI-RLZ User rank is Captain (20000 - 30000 Reputation Level)IOI-RLZ User rank is Captain (20000 - 30000 Reputation Level)IOI-RLZ User rank is Captain (20000 - 30000 Reputation Level)IOI-RLZ User rank is Captain (20000 - 30000 Reputation Level)IOI-RLZ User rank is Captain (20000 - 30000 Reputation Level)IOI-RLZ User rank is Captain (20000 - 30000 Reputation Level)  Folding Points: 7098 Folding Title: Novice Folder
Time spent in forums: 1 Week 5 Days 12 h 44 m 28 sec
Reputation Power: 213
Send a message via MSN to IOI-RLZ Send a message via Yahoo to IOI-RLZ
Starting out with haskell.

Hi,

I just started in haskell, but couldn't find much material, I have two books
#1 Haskell Road to Logic Math and Programming
#2 Craft of Haskell Programming.

If anyone has any more info on how to approach haskell and take it to the next level it will be much appreciated ..

thanks in advance...
__________________
The only Verdict is Vengeance a Vendetta held as a Votive, not in Vain, for the Value and Veracity of such shall one day Vindicate the Vigilant and the Virtuous


Mav RLZ AC/DC RLZ

Reply With Quote
  #2  
Old June 23rd, 2007, 12:26 AM
IOI-RLZ's Avatar
IOI-RLZ IOI-RLZ is offline
BANDITS 6'0 Clock !
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2006
Location: INDIYEAH !
Posts: 547 IOI-RLZ User rank is Captain (20000 - 30000 Reputation Level)IOI-RLZ User rank is Captain (20000 - 30000 Reputation Level)IOI-RLZ User rank is Captain (20000 - 30000 Reputation Level)IOI-RLZ User rank is Captain (20000 - 30000 Reputation Level)IOI-RLZ User rank is Captain (20000 - 30000 Reputation Level)IOI-RLZ User rank is Captain (20000 - 30000 Reputation Level)IOI-RLZ User rank is Captain (20000 - 30000 Reputation Level)IOI-RLZ User rank is Captain (20000 - 30000 Reputation Level)IOI-RLZ User rank is Captain (20000 - 30000 Reputation Level)  Folding Points: 7098 Folding Title: Novice Folder
Time spent in forums: 1 Week 5 Days 12 h 44 m 28 sec
Reputation Power: 213
Send a message via MSN to IOI-RLZ Send a message via Yahoo to IOI-RLZ
Quote:
Define a function removeFst that removes the first occurrence of
an integer 'n' from a list of integers. If n does not occur in the list, the list remains
unchanged.


thing is while I can tell whether or not that integer n is present or not,
Code:
removeFst :: Int -> [Int] -> bool
removeFst n [] 		= error "your list is empty"
removeFst n [x] 	| n == x		= True
					| otherwise 	= False
removeFst n (x:xs)	| n == x 		= True
					| otherwise 	= removeFst n xs 

how do I remove that element. I tried replacing True with
Code:
Delete n [x]
but to no avail.

Thanks in advance ...

Reply With Quote
  #3  
Old June 26th, 2007, 06:41 AM
jamieB jamieB is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2002
Posts: 592 jamieB User rank is Sergeant (500 - 2000 Reputation Level)jamieB User rank is Sergeant (500 - 2000 Reputation Level)jamieB User rank is Sergeant (500 - 2000 Reputation Level)jamieB User rank is Sergeant (500 - 2000 Reputation Level)jamieB User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 1 h 56 m 16 sec
Reputation Power: 17
Doing exercises like this is good practice, and so is reading the Prelude - `delete' is defined there like this:

Code:
-- | 'delete' @x@ removes the first occurrence of @x@ from its list argument.
-- For example,
--
-- > delete 'a' "banana" == "bnana"
--
-- It is a special case of 'deleteBy', which allows the programmer to
-- supply their own equality test.

delete                  :: (Eq a) => a -> [a] -> [a]
delete                  =  deleteBy (==)

-- | The 'deleteBy' function behaves like 'delete', but takes a
-- user-supplied equality predicate.
deleteBy                :: (a -> a -> Bool) -> a -> [a] -> [a]
deleteBy _  _ []        = []
deleteBy eq x (y:ys)    = if x `eq` y then ys else y : deleteBy eq x ys




Use hoogle.com too, to find functions by their type signatures. You know this must require instances of Eq, and is a function from lists to lists. Lo and behold, hoogling "Eq a => [a] -> [a]" gets results.
Comments on this post
IOI-RLZ agrees: agrees

Last edited by jamieB : June 26th, 2007 at 06:46 AM.

Reply With Quote
  #4  
Old June 26th, 2007, 06:45 AM
jamieB jamieB is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2002
Posts: 592 jamieB User rank is Sergeant (500 - 2000 Reputation Level)jamieB User rank is Sergeant (500 - 2000 Reputation Level)jamieB User rank is Sergeant (500 - 2000 Reputation Level)jamieB User rank is Sergeant (500 - 2000 Reputation Level)jamieB User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 1 h 56 m 16 sec
Reputation Power: 17
Quote:
Originally Posted by IOI-RLZ
Hi,

I just started in haskell, but couldn't find much material, I have two books
#1 Haskell Road to Logic Math and Programming
#2 Craft of Haskell Programming.

If anyone has any more info on how to approach haskell and take it to the next level it will be much appreciated ..

thanks in advance...


Keep at it, write some code, set yourself goals for actual programs you want to write. E.g. I tried the ruby quiz puzzles in haskell (http://www.rubyquiz.com/) and put some solutions on the haskell wiki.

And look out for Don Stewarts O'Reilly book Practical Haskell (later in the year?).

Reply With Quote
  #5  
Old June 26th, 2007, 06:51 AM
jamieB jamieB is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2002
Posts: 592 jamieB User rank is Sergeant (500 - 2000 Reputation Level)jamieB User rank is Sergeant (500 - 2000 Reputation Level)jamieB User rank is Sergeant (500 - 2000 Reputation Level)jamieB User rank is Sergeant (500 - 2000 Reputation Level)jamieB User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 1 h 56 m 16 sec
Reputation Power: 17
Quote:
Originally Posted by jamieB
Doing exercises like this is good practice, and so is reading the Prelude - `delete' is defined there like this:

....

Err, sorry - delete is in Data.List, not the prelude. I got that source code by following the link from hoogle and clicking on source code in the haddock docs. You should get in the habit of doing that.

Reply With Quote
  #6  
Old June 27th, 2007, 12:26 PM
IOI-RLZ's Avatar
IOI-RLZ IOI-RLZ is offline
BANDITS 6'0 Clock !
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2006
Location: INDIYEAH !
Posts: 547 IOI-RLZ User rank is Captain (20000 - 30000 Reputation Level)IOI-RLZ User rank is Captain (20000 - 30000 Reputation Level)IOI-RLZ User rank is Captain (20000 - 30000 Reputation Level)IOI-RLZ User rank is Captain (20000 - 30000 Reputation Level)IOI-RLZ User rank is Captain (20000 - 30000 Reputation Level)IOI-RLZ User rank is Captain (20000 - 30000 Reputation Level)IOI-RLZ User rank is Captain (20000 - 30000 Reputation Level)IOI-RLZ User rank is Captain (20000 - 30000 Reputation Level)IOI-RLZ User rank is Captain (20000 - 30000 Reputation Level)  Folding Points: 7098 Folding Title: Novice Folder
Time spent in forums: 1 Week 5 Days 12 h 44 m 28 sec
Reputation Power: 213
Send a message via MSN to IOI-RLZ Send a message via Yahoo to IOI-RLZ
Code:
{- creating a new list without n -}			
delete' :: a -> [a] -> [a]
delete' n [] 		= error "your list is empty"
delete' n [x] 		| n == x		= []
				| otherwise 	= [x]
delete' n (x:xs)	| n == x 		= delete' x xs
				| otherwise 	= x:delete' n xs


I got the above code working which basically removes elements in the list ==n

Hey feels good to know that there are people who know haskell, was beginning to think otherwise .

I am currently referring Haskell Road to Logic Math and Programming, and just started chapter 2, its a good book with the right mix of solved and unsolved problems.

#1 Well there was this exercise where I had to write a function blowup() that would do as follows >>
i/p "abcd" o/p "abbcccdddd"
and this is my solution
Code:
multiply' :: Char -> Int -> String
multiply' x y 	| y == 0  	= [] 
				| otherwise = x : multiply' x (y-1)
				
blowUP :: Int -> String -> String
blowUP y [] 	= []
blowUP  y (x:xs) = 	let
						ctr = y + 1 
						ch = x
						
					in ( multiply' ch ctr ) ++ ( blowUP  ctr xs )


getString' :: String -> String
getString' [] 	= []
getString' [x] 	= [x]
getString' xs = blowUP 0 xs 


The problem here is that I have to write an extra function getString' just to initialize the variable ctr ( which basically tells the number of times the char is to be repeated). Well in c++ I would use a global variable or preferrably static variables. What to do in haskell.

Mav ...

Reply With Quote
  #7  
Old June 27th, 2007, 01:26 PM
jamieB jamieB is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2002
Posts: 592 jamieB User rank is Sergeant (500 - 2000 Reputation Level)jamieB User rank is Sergeant (500 - 2000 Reputation Level)jamieB User rank is Sergeant (500 - 2000 Reputation Level)jamieB User rank is Sergeant (500 - 2000 Reputation Level)jamieB User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 1 h 56 m 16 sec
Reputation Power: 17
Quote:
Originally Posted by IOI-RLZ
Code:
{- creating a new list without n -}			
delete' :: a -> [a] -> [a]
delete' n [] 		= error "your list is empty"
delete' n [x] 		| n == x		= []
				| otherwise 	= [x]
delete' n (x:xs)	| n == x 		= delete' x xs
				| otherwise 	= x:delete' n xs


I got the above code working which basically removes elements in the list ==n

Hey feels good to know that there are people who know haskell, was beginning to think otherwise .

I am currently referring Haskell Road to Logic Math and Programming, and just started chapter 2, its a good book with the right mix of solved and unsolved problems.

#1 Well there was this exercise where I had to write a function blowup() that would do as follows >>
i/p "abcd" o/p "abbcccdddd"
and this is my solution
Code:
multiply' :: Char -> Int -> String
multiply' x y 	| y == 0  	= [] 
				| otherwise = x : multiply' x (y-1)
				
blowUP :: Int -> String -> String
blowUP y [] 	= []
blowUP  y (x:xs) = 	let
						ctr = y + 1 
						ch = x
						
					in ( multiply' ch ctr ) ++ ( blowUP  ctr xs )


getString' :: String -> String
getString' [] 	= []
getString' [x] 	= [x]
getString' xs = blowUP 0 xs 


The problem here is that I have to write an extra function getString' just to initialize the variable ctr ( which basically tells the number of times the char is to be repeated). Well in c++ I would use a global variable or preferrably static variables. What to do in haskell.

Mav ...

The Road to Logic was the first Haskell book I read -- I think it's excellent too.

One mistake you're making above is in pattern matching - you only need to match [] and (x:xs) because [x] matches (x:xs) where xs == [] (you still need to match [x] if you need to handle the singleton list specially).

You do need a helper function of some sort I think. Here's a solution:

Code:
blowup :: [a] -> [a]
blowup xs = blowup' xs 1
    where blowup' [] _ = []
          blowup' (x:xs) n = take n (repeat x) ++ blowup' xs (n+1)


My advice is to post your future questions to the haskell-cafe mailing list - you'll get inundated with high quality help!

Good luck with the book and with haskell.

Reply With Quote
  #8  
Old June 27th, 2007, 01:45 PM
IOI-RLZ's Avatar
IOI-RLZ IOI-RLZ is offline
BANDITS 6'0 Clock !
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2006
Location: INDIYEAH !
Posts: 547 IOI-RLZ User rank is Captain (20000 - 30000 Reputation Level)IOI-RLZ User rank is Captain (20000 - 30000 Reputation Level)IOI-RLZ User rank is Captain (20000 - 30000 Reputation Level)IOI-RLZ User rank is Captain (20000 - 30000 Reputation Level)IOI-RLZ User rank is Captain (20000 - 30000 Reputation Level)IOI-RLZ User rank is Captain (20000 - 30000 Reputation Level)IOI-RLZ User rank is Captain (20000 - 30000 Reputation Level)IOI-RLZ User rank is Captain (20000 - 30000 Reputation Level)IOI-RLZ User rank is Captain (20000 - 30000 Reputation Level)  Folding Points: 7098 Folding Title: Novice Folder
Time spent in forums: 1 Week 5 Days 12 h 44 m 28 sec
Reputation Power: 213
Send a message via MSN to IOI-RLZ Send a message via Yahoo to IOI-RLZ
Thanks man..

but where is this haskell-cafe mailing list

Reply With Quote
  #9  
Old June 27th, 2007, 01:55 PM
jamieB jamieB is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2002
Posts: 592 jamieB User rank is Sergeant (500 - 2000 Reputation Level)jamieB User rank is Sergeant (500 - 2000 Reputation Level)jamieB User rank is Sergeant (500 - 2000 Reputation Level)jamieB User rank is Sergeant (500 - 2000 Reputation Level)jamieB User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 1 h 56 m 16 sec
Reputation Power: 17
Quote:
Originally Posted by IOI-RLZ
Thanks man..

but where is this haskell-cafe mailing list

here if you want to use it as a mailing list or here if you want to post to it like a forum.

Also, check out the #haskell irc channel of freenode - very friendly and helpful place.

Reply With Quote
  #10  
Old June 27th, 2007, 02:37 PM
jamieB jamieB is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2002
Posts: 592 jamieB User rank is Sergeant (500 - 2000 Reputation Level)jamieB User rank is Sergeant (500 - 2000 Reputation Level)jamieB User rank is Sergeant (500 - 2000 Reputation Level)jamieB User rank is Sergeant (500 - 2000 Reputation Level)jamieB User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 1 h 56 m 16 sec
Reputation Power: 17
Quote:
Originally Posted by jamieB
You do need a helper function of some sort I think. Here's a solution:

You can always do without a helper function if you really want to:

Code:
blowup = foldr (\(n,x) ys -> (take n (repeat x)) ++ ys) [] . zip [1..] 


Also, anything you can write with direct recursion (a base case for the empty list, or zero etc, and a case for everything else) can be written with a higher order recursive function like foldr, and it's often a good idea to do so even if it's sometimes less easy to read. Not that it matters in this case......

Last edited by jamieB : June 27th, 2007 at 02:41 PM.

Reply With Quote
  #11  
Old June 27th, 2007, 02:45 PM
jamieB jamieB is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2002
Posts: 592 jamieB User rank is Sergeant (500 - 2000 Reputation Level)jamieB User rank is Sergeant (500 - 2000 Reputation Level)jamieB User rank is Sergeant (500 - 2000 Reputation Level)jamieB User rank is Sergeant (500 - 2000 Reputation Level)jamieB User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 1 h 56 m 16 sec
Reputation Power: 17
I'm chatting away to myself here, but this reminds of something funny - evolution of a haskell programmer
Comments on this post
IOI-RLZ agrees: hehe ... the last solution had me in splits ... nice to know there are people in haskell here at
dev...

Reply With Quote
  #12  
Old July 1st, 2007, 07:10 AM
IOI-RLZ's Avatar
IOI-RLZ IOI-RLZ is offline
BANDITS 6'0 Clock !
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2006
Location: INDIYEAH !
Posts: 547 IOI-RLZ User rank is Captain (20000 - 30000 Reputation Level)IOI-RLZ User rank is Captain (20000 - 30000 Reputation Level)IOI-RLZ User rank is Captain (20000 - 30000 Reputation Level)IOI-RLZ User rank is Captain (20000 - 30000 Reputation Level)IOI-RLZ User rank is Captain (20000 - 30000 Reputation Level)IOI-RLZ User rank is Captain (20000 - 30000 Reputation Level)IOI-RLZ User rank is Captain (20000 - 30000 Reputation Level)IOI-RLZ User rank is Captain (20000 - 30000 Reputation Level)IOI-RLZ User rank is Captain (20000 - 30000 Reputation Level)  Folding Points: 7098 Folding Title: Novice Folder
Time spent in forums: 1 Week 5 Days 12 h 44 m 28 sec
Reputation Power: 213
Send a message via MSN to IOI-RLZ Send a message via Yahoo to IOI-RLZ
I had posted this thread at nabble, but then I checked a couple of days later that I had received an e-mail from nabble that I wasn't eligible for the mailing list, is this because I posted in haskell-haskell instead of haskell-cafe ?

I am not going to join any IRC anytime soon, lest they roast me!

Reply With Quote
  #13  
Old July 1st, 2007, 09:00 AM
jamieB jamieB is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2002
Posts: 592 jamieB User rank is Sergeant (500 - 2000 Reputation Level)jamieB User rank is Sergeant (500 - 2000 Reputation Level)jamieB User rank is Sergeant (500 - 2000 Reputation Level)jamieB User rank is Sergeant (500 - 2000 Reputation Level)jamieB User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 1 h 56 m 16 sec
Reputation Power: 17
Quote:
Originally Posted by IOI-RLZ