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: Are these soloutions all valid and a good use of Haskell
(Roelof Wobben)
2. Re: Are these soloutions all valid and a good use of Haskell
(Alex Hammel)
3. Finding Keith Numbers with Haskell (Jack Mott)
4. Re: Finding Keith Numbers with Haskell (Rein Henrichs)
5. Haskell and LiveCode (Frank)
6. Re: Are these soloutions all valid and a good use of Haskell
(Roelof Wobben)
7. Re: Are these soloutions all valid and a good use of Haskell
(Julian Birch)
----------------------------------------------------------------------
Message: 1
Date: Mon, 10 Nov 2014 21:48:11 +0100
From: Roelof Wobben <[email protected]>
To: [email protected], The Haskell-Beginners Mailing List -
Discussion of primarily beginner-level topics related to Haskell
<[email protected]>
Subject: Re: [Haskell-beginners] Are these soloutions all valid and a
good use of Haskell
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8; format=flowed
Roelof Wobben schreef op 10-11-2014 20:59:
> last5 :: [a] -> Maybe a
> last5 = foldr acc Nothing where
> acc x Nothing = Just x
> acc _ j = j
When I enter this in GHCI I see this error :
Illegal type signature: ?[a] -> Maybe a last5?
------------------------------
Message: 2
Date: Mon, 10 Nov 2014 13:47:05 -0800
From: Alex Hammel <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Are these soloutions all valid and a
good use of Haskell
Message-ID:
<ca+_xfeqhp2djwdkbvoyqaxwmsgeqx1xvuasn8hwxrxb8a-c...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
It's an indentation issue. Make sure that there are no spaces before the
bit about 'last5 = foldr acc' etc.
On Mon, Nov 10, 2014 at 12:48 PM, Roelof Wobben <[email protected]> wrote:
> Roelof Wobben schreef op 10-11-2014 20:59:
>
>> last5 :: [a] -> Maybe a
>> last5 = foldr acc Nothing where
>> acc x Nothing = Just x
>> acc _ j = j
>>
>
> When I enter this in GHCI I see this error :
>
> Illegal type signature: ?[a] -> Maybe a last5?
>
>
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20141110/828046f0/attachment-0001.html>
------------------------------
Message: 3
Date: Mon, 10 Nov 2014 18:32:14 -0600
From: Jack Mott <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] Finding Keith Numbers with Haskell
Message-ID:
<CAOu+pyhsFWKMLk+fq2hP490NA6xjk_SXnvG=bgj3tpi55uk...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
I'm on day 2 of learning Haskell, and decided to write a program to find
Keith Numbers as my first project. So far so good, I have some code that
does the job (see below). First I would just like to ask others to look it
over and let me know if I am doing anything particularly wrong or not
advised here.
Also, I am using the "isKeithHelper" function because I didn't know how to
make use of the filter function directly with isKeith, because isKeith
takes two parameters. I'm pretty sure there is a better way to handle
that, any tips?
Lastly, I'd like to make this as efficient as possible. At the moment I am
adding [s] to the end of the list in the isKeith function, which I know is
O(n) instead of O(1). I don't think there is a way to avoid either that or
having to use drop which would have the same downside. Is this a case
where a Sequence or Vector might be more useful? How would I convert this
to use a Sequence instead?
import Data.Time.Clock.POSIX
import Data.Digits
isKeith :: Integer -> [Integer] -> Bool
isKeith n l
| s == n = True
| s > n = False
| otherwise = isKeith n x (l ++ [s])
where
s = sum l
isKeithHelper :: Integer -> Bool
isKeithHelper n = isKeith n (digits 10 n)
main :: IO ()
main = do
start <- getPOSIXTime
print (filter isKeithHelper [1000..9999])
end <- getPOSIXTime
print (end - start)
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20141110/1d202443/attachment-0001.html>
------------------------------
Message: 4
Date: Mon, 10 Nov 2014 18:50:23 -0800
From: Rein Henrichs <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Finding Keith Numbers with Haskell
Message-ID:
<CAJp6G8y_tci=40tzhs-ad2ykmp4vv8gcg5un6vmkbw3jkm5...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Since summing is commutative (sum [a,b] = sum [b,a]), it doesn't matter
what order they appear in. You can start out by reversing the digits and
then by taking from and adding to the beginning of the list instead of the
end. Also, isKeith needs to know the length of the decimal representation
of n. Since you are already computing that representation in isKeithHelper,
it might be best to compute this there as well and pass it into isKeith.
(Also please consider the criterion library for benchmarking.)
> import Data.Digits
> isKeith :: Int -> Bool
> isKeith n = let ds = digitsRev 10 n in isKeith' n (length ds) ds
> isKeith' :: Int -> Int -> [Int] -> Bool
> isKeith' n len ds
> | n == s = True
> | s > n = False
> | otherwise = isKeith' n len (take len (s : ds))
> where s = sum ds
> main :: IO ()
> main = print (isKeith 197)
True
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20141110/3afec4a3/attachment-0001.html>
------------------------------
Message: 5
Date: Tue, 11 Nov 2014 01:01:05 -0500
From: Frank <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: [Haskell-beginners] Haskell and LiveCode
Message-ID:
<CA+a3wkJ5=quEX81d=nm2m8y-dcigkodzn0g8xsqsi6yqj7o...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
How do the 2 languages compare?
--
P.S.: I prefer to be reached on BitMessage at
BM-2D8txNiU7b84d2tgqvJQdgBog6A69oDAx6
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20141111/87ff7ed2/attachment-0001.html>
------------------------------
Message: 6
Date: Tue, 11 Nov 2014 08:20:40 +0100
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] Are these soloutions all valid and a
good use of Haskell
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20141111/fa9542c9/attachment-0001.html>
------------------------------
Message: 7
Date: Tue, 11 Nov 2014 08:35:13 +0000
From: Julian Birch <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Are these soloutions all valid and a
good use of Haskell
Message-ID:
<cab0tuzdmc7xc06gx6mh9g0kgeu+a2z_ygwuyc105xtmh2ry...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
_ just means "ignore this parameter, I'm not going to use it"
On Tuesday, November 11, 2014, Roelof Wobben <[email protected]> wrote:
> Thanks, this is working well.
>
> But just for understanding
>
> in the part acc x Nothing x is the input string,
> and in the part _j means the same as (xs:x)
>
> Roelof
>
>
>
> Alex Hammel schreef op 10-11-2014 22:47:
>
> It's an indentation issue. Make sure that there are no spaces before the
> bit about 'last5 = foldr acc' etc.
>
> On Mon, Nov 10, 2014 at 12:48 PM, Roelof Wobben <[email protected]
> <javascript:_e(%7B%7D,'cvml','[email protected]');>> wrote:
>
>> Roelof Wobben schreef op 10-11-2014 20:59:
>>
>>> last5 :: [a] -> Maybe a
>>> last5 = foldr acc Nothing where
>>> acc x Nothing = Just x
>>> acc _ j = j
>>>
>>
>> When I enter this in GHCI I see this error :
>>
>> Illegal type signature: ?[a] -> Maybe a last5?
>>
>>
>>
>>
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> <javascript:_e(%7B%7D,'cvml','[email protected]');>
>> http://www.haskell.org/mailman/listinfo/beginners
>>
>
>
>
> _______________________________________________
> Beginners mailing [email protected]
> <javascript:_e(%7B%7D,'cvml','[email protected]');>http://www.haskell.org/mailman/listinfo/beginners
>
>
>
--
Sent from an iPhone, please excuse brevity and typos.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20141111/bb3c67c6/attachment.html>
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 77, Issue 11
*****************************************