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: associative arrays (Patrick Redmond)
2. A simple function (Ezequiel Hernan Di Giorgi)
3. Re: A simple function (Ertugrul S?ylemez)
4. Re: A simple function (David McBride)
5. Re: A simple function (Lyndon Maydwell)
6. First version of GHC (D?niel Arat?)
7. Misc items (KMandPJLynch)
8. Re: Misc items (Edward Z. Yang)
9. Re: First version of GHC (Jonas Almstr?m Dureg?rd)
----------------------------------------------------------------------
Message: 1
Date: Thu, 30 Aug 2012 07:37:52 -0400
From: Patrick Redmond <[email protected]>
Subject: Re: [Haskell-beginners] associative arrays
To: [email protected]
Message-ID:
<cahuea4eozeynlfpgdkgg43so4fropn3uose+2possxujoqo...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8
> On 29.08.2012 10:19, Karl Voelker wrote:
>> Data.Map.lookup has better asymptotic time complexity than
>> Prelude.lookup, but the relevant measures of efficiency depend on the
>> situation.
On Wed, Aug 29, 2012 at 2:25 AM, Dmitry Vyal <[email protected]> wrote:
> Can you please elaborate a bit? I suspect lists better when there are just
> a few elements, but how much is a "few"?
I believe that Prelude.lookup looks through the list until it finds
the thing you're looking for or exhausts the list [this is something
like O(n)]. Data.Map performs a binary search over its tree [this is
something like O(log n)]
> And what's about storage
> efficiency? How big is (Data.Map.fromList [1])?
A map associates keys and values, so your example doesn't actually
work. As for space efficiency, I'm sure that an association tree and
an association list are simple enough that both grow linearly with the
number of elements.
Prelude> :m +Data.Map
Prelude Data.Map> let x = fromList [("banana", ["yellow"]), ("apple",
["green", "red"]), ("tomato", ["red"])]
Prelude Data.Map> x
Prelude Data.Map> Data.Map.lookup "apple" x
Just ["green","red"]
Prelude Data.Map> Data.Map.lookup "fish" x
Nothing
------------------------------
Message: 2
Date: Thu, 30 Aug 2012 09:52:42 -0300
From: Ezequiel Hernan Di Giorgi <[email protected]>
Subject: [Haskell-beginners] A simple function
To: [email protected]
Message-ID:
<CAHRx9szoQUU80PBaV-8WzDC+G2_sO0DWpir=kcrrhtw0xrp...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Hallo liebe Leute. Hola gente. I'm starting with Haskell and i have some
problems:
*intercalate :: [t] -> [t] -> [t]*
*intercalate [a,b] [c,d] = [a,c,b,d]*
*intercalate (_) (_) = error "JOJO u cant do this"*
Are there any form to restrict the parmaters that only allow to call the
function *intercalate* with two arrays of two elements, in compilation
time? Cause i cant write* intercalete :: [t,t] -> [t,t]->[t,t,t,t]*.
Sorry for my bad english. I'm Argentinean.
Thanks!
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20120830/ea7d2d8e/attachment-0001.htm>
------------------------------
Message: 3
Date: Thu, 30 Aug 2012 15:12:29 +0200
From: Ertugrul S?ylemez <[email protected]>
Subject: Re: [Haskell-beginners] A simple function
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"
Ezequiel Hernan Di Giorgi <[email protected]> wrote:
> Hallo liebe Leute. Hola gente. I'm starting with Haskell and i have
> some problems:
>
> *intercalate :: [t] -> [t] -> [t]*
> *intercalate [a,b] [c,d] = [a,c,b,d]*
> *intercalate (_) (_) = error "JOJO u cant do this"*
>
> Are there any form to restrict the parmaters that only allow to call
> the function *intercalate* with two arrays of two elements, in
> compilation time? Cause i cant write* intercalete :: [t,t] ->
> [t,t]->[t,t,t,t]*.
Yes and no. It's possible, but what you're having is then not a list,
because a list has the property that it can hold an arbitrary amount of
elements. The simplest way is to use tuples:
intercalate :: (a, a) -> (a, a) -> [a]
intercalate (a, b) (c, d) = [a, b, c, d]
But that function does not look terribly useful to me, so the first
question you should ask yourself is: Do you actually want to restrict
this to exactly two elements or do you want to restrict it to lists of
the same length? If it's the latter it gets more interesting, but is
also more involved. Here is a simple way to do it using the GADTs
extension:
data List :: * -> * -> * where
Nil :: List () a
Cons :: a -> List n a -> List (Maybe n) a
intercalate :: List n a -> List n a -> [a]
intercalate (Cons x xs) (Cons y ys) = x : y : intercalate xs ys
intercalate Nil Nil = []
As you see what we have here is something that looks like a list and
behaves like a list on the value level, but on the type level it's
something different, something smarter:
Nil :: List () Int
Cons 3 Nil :: List (Maybe ()) Int
Cons 3 (Cons 4 Nil) :: List (Maybe (Maybe ())) Int
Now the length of the list is encoded on the type level and you can
match against it.
Greets,
Ertugrul
--
Not to be or to be and (not to be or to be and (not to be or to be and
(not to be or to be and ... that is the list monad.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20120830/a605773e/attachment-0001.pgp>
------------------------------
Message: 4
Date: Thu, 30 Aug 2012 09:14:34 -0400
From: David McBride <[email protected]>
Subject: Re: [Haskell-beginners] A simple function
To: Ezequiel Hernan Di Giorgi <[email protected]>
Cc: [email protected]
Message-ID:
<CAN+Tr41Np=4cumv4gbtjhtmeyfxngfrybk9zsycia_h4ndb...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
intercalate (a:b:_) (c:d:_) = [a,c,b,d]
On Thu, Aug 30, 2012 at 8:52 AM, Ezequiel Hernan Di Giorgi <
[email protected]> wrote:
> Hallo liebe Leute. Hola gente. I'm starting with Haskell and i have some
> problems:
>
> *intercalate :: [t] -> [t] -> [t]*
> *intercalate [a,b] [c,d] = [a,c,b,d]*
> *intercalate (_) (_) = error "JOJO u cant do this"*
>
>
> Are there any form to restrict the parmaters that only allow to call the
> function *intercalate* with two arrays of two elements, in compilation
> time? Cause i cant write* intercalete :: [t,t] -> [t,t]->[t,t,t,t]*.
>
> Sorry for my bad english. I'm Argentinean.
>
> Thanks!
>
> _______________________________________________
> 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/20120830/6e828791/attachment-0001.htm>
------------------------------
Message: 5
Date: Thu, 30 Aug 2012 21:17:54 +0800
From: Lyndon Maydwell <[email protected]>
Subject: Re: [Haskell-beginners] A simple function
To: Ezequiel Hernan Di Giorgi <[email protected]>
Cc: [email protected]
Message-ID:
<cam5qztybfbjosyxuxdes2gdo6zahvd6c5b5xtdyt6ltk5+c...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8
Probably the easiest way to ensure this at compile time would be to
use tuples for the arguments:
intercalate :: (t,t) -> (t,t)->[t]
And for the result too, if you care about the length of it:
intercalate :: (t,t) -> (t,t) -> (t,t,t,t)
There are certain packages that allow for size-indexed list-like types
such as HList and Data.Vec, although these are usually considered as
not terribly beginner friendly due to type-encoded naturals, etc.
Is there a particular reason why you want to create such an
intercalate function? It might help with suggesting an approach.
On Thu, Aug 30, 2012 at 8:52 PM, Ezequiel Hernan Di Giorgi
<[email protected]> wrote:
> Hallo liebe Leute. Hola gente. I'm starting with Haskell and i have some
> problems:
>
> intercalate :: [t] -> [t] -> [t]
> intercalate [a,b] [c,d] = [a,c,b,d]
> intercalate (_) (_) = error "JOJO u cant do this"
>
>
> Are there any form to restrict the parmaters that only allow to call the
> function intercalate with two arrays of two elements, in compilation time?
> Cause i cant write intercalete :: [t,t] -> [t,t]->[t,t,t,t].
>
> Sorry for my bad english. I'm Argentinean.
>
> Thanks!
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
------------------------------
Message: 6
Date: Thu, 30 Aug 2012 16:13:34 +0200
From: D?niel Arat? <[email protected]>
Subject: [Haskell-beginners] First version of GHC
To: [email protected]
Message-ID:
<cahvkd2+4wgepidzgvtzn+cqn1udjtkveksnvjxsxsgsbk26...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1
Hi all,
I'm curious if the first implementation of GHC was in a different
language before its current instance could be developed.
If yes, what language was used?
If not, what compiler was first used to compile GHC?
Thank you,
Daniel
------------------------------
Message: 7
Date: Thu, 30 Aug 2012 10:39:14 -0400
From: KMandPJLynch <[email protected]>
Subject: [Haskell-beginners] Misc items
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
Good morning,
A comment such as [which begins with -- followed immediately by a period '.' -
see next line]:
--...
creates the syntax error:
ch11.hs:228:1: parse error on input `--...'
I'd appreciate any advice.
Good day
------------------------------
Message: 8
Date: Thu, 30 Aug 2012 10:46:46 -0400
From: "Edward Z. Yang" <[email protected]>
Subject: Re: [Haskell-beginners] Misc items
To: KMandPJLynch <[email protected]>
Cc: beginners <[email protected]>
Message-ID: <1346337917-sup-5615@javelin>
Content-Type: text/plain; charset=UTF-8
Hello,
This is because -- appended by a symbol results in the dashes
being parsed as an operator. Add a space.
Cheers,
Edward
Excerpts from KMandPJLynch's message of Thu Aug 30 10:39:14 -0400 2012:
> Good morning,
>
> A comment such as [which begins with -- followed immediately by a period '.'
> - see next line]:
> --...
> creates the syntax error:
> ch11.hs:228:1: parse error on input `--...'
>
> I'd appreciate any advice.
>
> Good day
>
------------------------------
Message: 9
Date: Thu, 30 Aug 2012 17:27:02 +0200
From: Jonas Almstr?m Dureg?rd <[email protected]>
Subject: Re: [Haskell-beginners] First version of GHC
To: D?niel Arat? <[email protected]>
Cc: [email protected]
Message-ID:
<CAGNgccax=ifdmmp6ysbo6f7qdsk_yeebkeieb2dfkxsqu2x...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1
Hi,
According to the GHC wikipedia page, a prototype was written in Lazy
ML. Whether this prototype was used to bootstrap the Haskell version
is not specified.
Regards,
Jonas
On 30 August 2012 16:13, D?niel Arat? <[email protected]> wrote:
> Hi all,
>
> I'm curious if the first implementation of GHC was in a different
> language before its current instance could be developed.
> If yes, what language was used?
> If not, what compiler was first used to compile GHC?
>
> Thank you,
> Daniel
>
> _______________________________________________
> 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 50, Issue 38
*****************************************