Haskell beginner question

52 views
Skip to first unread message

Abhinav Gogna

unread,
Dec 19, 2014, 3:44:07 PM12/19/14
to haskel...@googlegroups.com
Going through learn you a haskell.

In recursion chapter, there is an implementation of take function. I am trying to implement it another way but keep getting compiler error "Not in scope: ‘as’"

Here is the code
take' :: Int -> [a] -> [a]
take'
_ [] = []
take
' x _
  | x _ <= 0 = []
  | otherwise x (a:as) = a : take'
(x-1) as

Can someone tell me what is wrong with this program?

Derek McLoughlin

unread,
Dec 20, 2014, 8:06:08 AM12/20/14
to haskel...@googlegroups.com
Guards are just boolean conditions, and you can't (without using an extension called PatternGuards) do pattern matching in them:

take' :: Int -> [a] -> [a]
take' _ [] = []
take' x (a:as)
  | x <= 0 = []
  | otherwise = a : take' (x-1) as

Abhinav Gogna

unread,
Dec 22, 2014, 2:40:31 PM12/22/14
to haskel...@googlegroups.com
Thank you Derek!

mustafa mert güntürkün

unread,
Jan 5, 2015, 8:13:21 AM1/5/15
to haskel...@googlegroups.com
Hi all i have a question;

im going to be final exam today 2 hour later.I should know ;

Haskell's address binding mechanism for these

-static 
-stack-dynamic
-explicit heap-dynamic and implicit heap-dynamic if u know the answer could u send me pls.. 

Thank you.
Reply all
Reply to author
Forward
0 new messages