Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/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: accumenlator problem (Nishant)
2. Re: accumenlator problem (Roelof Wobben)
3. can I have a case statement with a pattern matching
(Roelof Wobben)
4. Function Composition (Shishir Srivastava)
5. Re: Function Composition
(Sumit Sahrawat, Maths & Computing, IIT (BHU))
6. Re: can I have a case statement with a pattern matching (Nishant)
----------------------------------------------------------------------
Message: 1
Date: Wed, 13 May 2015 17:34:53 +0530
From: Nishant <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] accumenlator problem
Message-ID:
<caeqdmz6agtxfzpscqdkmbada8av3b5xfcbuutrd9xxl786l...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
I think you wanted something like this :
toDigits :: Integer -> [Integer]
toDigits number
| number <= 0 = []
| number > 0 = toDigitsAcc [] number --( toDigits (number `div` 10) ) ++
[number `mod` 10]
toDigitsAcc:: [Integer] -> Integer -> [Integer]
toDigitsAcc acc number
| number <= 0 = acc
| number > 0 = toDigitsAcc ((number `mod` 10) : acc) (number `div` 10)
Regards
Nishant Verma
On Wed, May 13, 2015 at 5:13 PM, Roelof Wobben <[email protected]> wrote:
> Hello,
>
> I have this :
>
> -- | Convert a digit to a list for example 123 becomes [1,2,3]
> toDigits :: Integer -> [Integer]
> toDigits number
> | number <= 0 = []
> | number > 0 = toDigitsAcc [] number
>
> toDigitsAcc:: [Integer] -> [Integer] -> [Integer]
> toDigitsAcc acc number
> | number <= 0 = acc
> | number > 0 = (number `mod` 10) : acc toDigitsAcc (number `div` 10)
>
> bur there are error on both last lines of he functions.
>
> Any tips how to solve this ?
>
> Roelof
>
>
> ---
> Dit e-mailbericht is gecontroleerd op virussen met Avast antivirussoftware.
> http://www.avast.com
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
--
Nishant
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150513/a396b025/attachment-0001.html>
------------------------------
Message: 2
Date: Wed, 13 May 2015 14:11:29 +0200
From: Roelof Wobben <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] accumenlator problem
Message-ID: <[email protected]>
Content-Type: text/plain; charset=windows-1252; format=flowed
Nishant schreef op 13-5-2015 om 14:04:
> number > 0 = toDigitsAcc ((number `mod` 10) : acc) (number `div` 10)
Thanks, I now see where my thinking took the wrong way
Roelof
---
Dit e-mailbericht is gecontroleerd op virussen met Avast antivirussoftware.
http://www.avast.com
------------------------------
Message: 3
Date: Wed, 13 May 2015 18:52:38 +0200
From: Roelof Wobben <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: [Haskell-beginners] can I have a case statement with a
pattern matching
Message-ID: <[email protected]>
Content-Type: text/plain; charset=windows-1252; format=flowed
Hello,
I try to make make the assignment of CIS194 where I must multiply every
second item from the right by 2
So I thought this could be working :
-- | Convert a digit to a reversed list for example 123 becomes [3,2,1]
revtoDigits :: Integer -> [Integer]
revtoDigits number
| number <= 0 = []
| number > 0 = number`mod` 10 : revtoDigits (number `div` 10)
-- | Convert a digit to a list for example 123 becomes [1,2,3]
toDigits :: Integer -> [Integer]
toDigits number
| number <= 0 = []
| number > 0 = toDigitsAcc [] number
toDigitsAcc:: [Integer] -> Integer -> [Integer]
toDigitsAcc acc number
| number <= 0 = acc
| number > 0 = toDigitsAcc ((number `mod` 10) : acc) (number `div` 10)
doubleEveryOther :: [Integer] -> [Integer]
doubleEveryOther list = case (length list) `mod` 2 of 0 ->
doubleEveryOther [] = []
doubleEveryOther (x:y:xs) = x*2 : y : xs
(length list) `mod` 2 of 0 ->
doubleEveryOther [] = []
doubleEveryOther (x:y:xs) = x : y*2 : xs
-- | The main entry point.
main = print $ doubleEveryOther [1,2,3]
but apperantly you cannot have pattern matching after a case statement
because I get a error on the = of a empty list
Roelof
---
Dit e-mailbericht is gecontroleerd op virussen met Avast antivirussoftware.
http://www.avast.com
------------------------------
Message: 4
Date: Wed, 13 May 2015 22:12:21 +0100
From: Shishir Srivastava <[email protected]>
To: beginners <[email protected]>
Subject: [Haskell-beginners] Function Composition
Message-ID:
<cale5rtuwkjnhja5f+29u39axk96ww0vyu2aftnhaw0t9znh...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Hi,
Could someone please point out what is the difference between using $ and
parenthesis in the function composition below. Why does the first
expression work whereas the second fails.
---
$$ head.head$[[1,2],[3,4]]
1
$$ head.head([[1,2],[3,4]])
<interactive>:122:12:
Couldn't match expected type ?a -> [c]? with actual type ?[t0]?
Relevant bindings include
---
Thanks,
Shishir
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150513/221e5395/attachment-0001.html>
------------------------------
Message: 5
Date: Thu, 14 May 2015 02:52:43 +0530
From: "Sumit Sahrawat, Maths & Computing, IIT (BHU)"
<[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Function Composition
Message-ID:
<CAJbEW8O=k9tvzmetya5gtlv6z_y-samrmy7fxzdmqvuhd9y...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Function application has the strongest precedence, thus something like
fun1 . fun2 arg
is equivalent to
fun1 . (fun2 arg)
Now, ($) is the same as function application, but has lowest precedence
(even lower than (.)).
infixr 0 ($)
($) :: (a -> b) -> a -> b
f $ x = f x
Thus,
fun1 . fun2 $ arg
is equivalent to
(fun1 . fun2) $ arg
== (fun1 . fun2) arg { apply ($) }
On 14 May 2015 at 02:42, Shishir Srivastava <[email protected]>
wrote:
> Hi,
>
> Could someone please point out what is the difference between using $ and
> parenthesis in the function composition below. Why does the first
> expression work whereas the second fails.
> ---
> $$ head.head$[[1,2],[3,4]]
> 1
> $$ head.head([[1,2],[3,4]])
>
> <interactive>:122:12:
> Couldn't match expected type ?a -> [c]? with actual type ?[t0]?
> Relevant bindings include
> ---
> Thanks,
> Shishir
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
--
Regards
Sumit Sahrawat
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150514/563e78cc/attachment-0001.html>
------------------------------
Message: 6
Date: Thu, 14 May 2015 12:18:37 +0530
From: Nishant <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] can I have a case statement with a
pattern matching
Message-ID:
<CAEQDmz7trP1emQNQGVQuzaYZykwwxq+Spya7J=wz-jt0hmz...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
This will double very second digit in list. To do from right, just reverse
the list first and then apply doubleEverySecond and then reverse back.
doubleEveryOther :: [Integer] -> [Integer]
doubleEveryOther [] = []
doubleEveryOther (x : []) = [x]
doubleEveryOther (x : y : []) = x : (2 * y) : []
doubleEveryOther (x:y:xs) = x : (2 * y) : doubleEveryOther (xs)
On Wed, May 13, 2015 at 10:22 PM, Roelof Wobben <[email protected]> wrote:
> Hello,
>
> I try to make make the assignment of CIS194 where I must multiply every
> second item from the right by 2
>
> So I thought this could be working :
>
> -- | Convert a digit to a reversed list for example 123 becomes [3,2,1]
> revtoDigits :: Integer -> [Integer]
> revtoDigits number
> | number <= 0 = []
> | number > 0 = number`mod` 10 : revtoDigits (number `div` 10)
>
> -- | Convert a digit to a list for example 123 becomes [1,2,3]
> toDigits :: Integer -> [Integer]
> toDigits number
> | number <= 0 = []
> | number > 0 = toDigitsAcc [] number
>
> toDigitsAcc:: [Integer] -> Integer -> [Integer]
> toDigitsAcc acc number
> | number <= 0 = acc
> | number > 0 = toDigitsAcc ((number `mod` 10) : acc) (number `div` 10)
>
> doubleEveryOther :: [Integer] -> [Integer]
> doubleEveryOther list = case (length list) `mod` 2 of 0 ->
> doubleEveryOther [] = []
> doubleEveryOther (x:y:xs) = x*2 : y : xs
> (length list) `mod` 2 of 0 ->
> doubleEveryOther [] = []
> doubleEveryOther (x:y:xs) = x : y*2 : xs
>
>
> -- | The main entry point.
> main = print $ doubleEveryOther [1,2,3]
>
>
> but apperantly you cannot have pattern matching after a case statement
> because I get a error on the = of a empty list
>
> Roelof
>
>
> ---
> Dit e-mailbericht is gecontroleerd op virussen met Avast antivirussoftware.
> http://www.avast.com
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
--
Nishant
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150514/3909a71c/attachment.html>
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 83, Issue 36
*****************************************