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: Creating Indexes (Christopher Reichert)
2. Re: Deploying a haskell application (not a webapp) (Ryan Trinkle)
3. Re: exercises/examples for streams (Pascal Knodel)
4. structural induction, two lists, simultaneous (Pascal Knodel)
----------------------------------------------------------------------
Message: 1
Date: Sun, 14 Dec 2014 09:41:39 -0600
From: Christopher Reichert <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Creating Indexes
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"
On Sun, Dec 14 2014, martin <[email protected]> wrote:
> Hello all,
>
> I recently wrote a Haskell program, which accesses Lists extensivly. That was
> okay to verify the overall idea, but
> performance degraded rapidly when I made the lists bigger. There was a
> quadratic effect and this was not surprizing,
> given the nature of the code.
>
Are you certain this was because of the List and not something else?
If you are constantly doing lookups on lists then, indeed, performance
will suffer.
> I am somewhat aware of Haskell types which offer faster access. But they all
> seem to assume that I know the way data is
> accessed when I write the type. A new access path may force me to rededign
> the type.
>
> What I am looking for is something which behaves like indexes in a RDBMS,
> i.e. to define a list-like type on an innocent
> data type (like a tuple) and then add indexes as needed. Is there such a
> thing?
Would an association list fit the model you are talking about?
ghci> let al = [ (1, "hello"), (2, "world") ]
ghci> Prelude.lookup 1 al
Just "hello"
ghci> Prelude.lookup 3 al
Nothing
You can then transform to Map (and back) easily:
ghci> Data.Map.fromList al
fromList [(1,"hello"),(2,"world")]
ghci> Data.Map.insert 42 "foo" $ fromList al
fromList [(1,"hello"),(2,"world"),(42,"foo")]
See Real World Haskell
(http://book.realworldhaskell.org/read/data-structures.html):
--
Christopher Reichert
irc: creichert
gpg: C81D 18C8 862A 3618 1376 FFA5 6BFC A992 9955 929B
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 818 bytes
Desc: not available
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20141214/ddbb1829/attachment-0001.sig>
------------------------------
Message: 2
Date: Sun, 14 Dec 2014 10:45:10 -0500
From: Ryan Trinkle <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Deploying a haskell application (not
a webapp)
Message-ID:
<cahnepixpleoi1gsoewdykdt-afqschh_uwyr9tqpvolzrca...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Duly noted! I didn't think an in-depth discussion of Nix would be on-topic
for this mailing list, but it looks like there's more interested than I
thought. When I get the chance to put something together, I'll make sure
to send out a link here.
On Sun, Dec 14, 2014 at 4:21 AM, Thomas Jakway <[email protected]> wrote:
>
> I'd be interested in reading that and am sure others would be too!
>
>
> On 12/13/14 1:01 PM, Norbert Melzer wrote:
>
> I'd think the details would be of general interest, why don't write an
> article/blogpost?
> Am 13.12.2014 18:50 schrieb "Ryan Trinkle" <[email protected]>:
>
>> I use Nix package manager for binary deployment of Haskell applications,
>> and it works great. Feel free to email me directly if you're interested in
>> the specifics.
>> On Dec 13, 2014 12:34 PM, "Alan Buxton" <[email protected]> wrote:
>>
>>> Hi thanks for the input so far.
>>>
>>>
>>>
>>> See attached a zipfile of a simplified version of the app. It runs
>>> locally on my dev machine and I want to be able to run it on a separate
>>> server. I don?t want to share the app with anyone else.
>>>
>>>
>>>
>>> If I do ?cabal install? with this particular application then it creates
>>> an executable at ~/.cabal/bin/app1
>>>
>>>
>>>
>>> If I copy that file onto the target server then I get the following
>>> output:
>>>
>>>
>>>
>>> $ ./app1 fred
>>>
>>> Hi fred
>>>
>>> Time now is 2014-12-13 17:27:21.764048 UTC
>>>
>>> app1: /home/alan/.cabal/share/app1-0.1.0.0/data/file1.txt: openFile:
>>> does not exist (No such file or directory)
>>>
>>>
>>>
>>> So sort of works but in particular the file attachment piece doesn?t
>>> work.
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> *From:* Beginners [mailto:[email protected]] *On Behalf Of
>>> *Kim-Ee
>>> Yeoh
>>> *Sent:* 13 December 2014 16:53
>>> *To:* The Haskell-Beginners Mailing List - Discussion of primarily
>>> beginner-level topics related to Haskell
>>> *Subject:* Re: [Haskell-beginners] Deploying a haskell application (not
>>> a webapp)
>>>
>>>
>>>
>>>
>>>
>>> On Sat, Dec 13, 2014 at 8:54 PM, Alan Buxton <[email protected]>
>>> wrote:
>>>
>>> I now want to deploy this application onto a separate server. This is
>>> not a webapp.
>>>
>>>
>>>
>>> Try as I might, Google will not point me in the direction of how to do
>>> this, apart from loads of links to Keter which is not what I want (there is
>>> no nginx or any other web server involved).
>>>
>>>
>>>
>>> Looks like there are some assumptions probably based on familiarity with
>>> some other language + toolchain.
>>>
>>> Of what is the haskell analogue you're looking for?
>>>
>>>
>>> -- Kim-Ee
>>>
>>> _______________________________________________
>>> Beginners mailing list
>>> [email protected]
>>> http://www.haskell.org/mailman/listinfo/beginners
>>>
>>>
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://www.haskell.org/mailman/listinfo/beginners
>>
>>
>
> _______________________________________________
> Beginners mailing
> [email protected]http://www.haskell.org/mailman/listinfo/beginners
>
>
>
> _______________________________________________
> 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/20141214/fc8be05d/attachment-0001.html>
------------------------------
Message: 3
Date: Sun, 14 Dec 2014 23:52:24 +0100
From: Pascal Knodel <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] exercises/examples for streams
Message-ID: <[email protected]>
Content-Type: text/plain; charset=windows-1252; format=flowed
Hi Carl,
--------------------------------------- snip
---------------------------------------
module BeginnerStreams where
-- 1. First try:
-- Contract: Input lists are sorted.
--
-- Notes:
--
-- (!) Duplicate elements are allowed.
-- (!) Sort `Left` before `Right`.
sorts :: Ord a => [a] -> [a] -> [Either a a]
sorts (l : ls) (r : rs)
| l <= r = Left l : sorts ls (r : rs)
| otherwise = Right r : sorts (l : ls) rs
-- l > r
sorts [] (r : rs) = Right r : sorts' Right rs
sorts (l : ls) [] = Left l : sorts' Left ls
sorts [] [] = []
sorts' e (i : is) = e i : sorts' e is
sorts' _ [] = []
-- The difficulty for me was: "Either".
-- I forgot about it while defining and
-- did wrong in defining the empty list
-- cases in my first definition:
--
-- sorts ls rs = ls ++ rs
--
-- That isn't possible without constructor application,
-- because of the output type "[Either a a]". Is it?
--
-- Wish there would be GHCi in the exam.
-- Where else did I fail and didn't notice it?
-- What higher order functions would you use to define "sorts"?
-- 2. First try:
-- I'm not sure, what do you mean by 'value itself'?
-- Why is the second tuple (2,1)? Ah, I see, is it sth. like:
--
-- [1,3] is index 0 and becomes (0,1), (03)
-- [2,3] 1 (1,2), (1,3)
-- ...
--
-- And those sorted in ascending order by the sum of the components?
-- Is it possible to stream this computation without blocking?
-- Is the list-of-lists sorted?
--------------------------------------- snip
---------------------------------------
The exercises from old exams that I have solved are at:
https://github.com/pascal-knodel/Programming-Paradigms-KIT-2014-2015/tree/master/3
Pascal
------------------------------
Message: 4
Date: Mon, 15 Dec 2014 02:42:09 +0100
From: Pascal Knodel <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] structural induction, two lists,
simultaneous
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8; format=flowed
Hi list,
Proposition:
map f (ys ++ zs) = map f ys ++ map f zs
(Haskell, the craft of functional programming, exercise 11.31)
Almost every time I'm asked to do (structural) induction over multiple
'things', in this example lists, I don't know how to do it.
(I encountered similar difficulties when I worked through chapter 9, see
https://github.com/pascal-knodel/haskell-craft/tree/master/Chapter%209 ,
ex. 9.5 ,
https://github.com/pascal-knodel/haskell-craft/blob/master/Chapter%209/E%279%27%275.hs).
I think my proof in this case isn't formally correct. It feels like it
isn't.
I would like to do the example with your help, so that I feel a
little bit safer.
Let's start with the base case. If I have two lists, do I select
one, say ys := [] . Only one or one after another? Or both 'parallel'?
I could state ys ++ zs := [] too, does it help?
I could imagine that the proposition could be expanded to something like
map f (l1 ++ l2 ++ ... ++ lN) = map f ys ++ map f zs
= map f l1 ++ map f l2 ++ ... ++ map f lN
And I could imagine that it is possible to do induction over more than
two lists too.
What is the reason why we can do it over two 'objects' at the same time?
How do I start? Can you explain this to me?
Attempt:
-- ---------------
-- 1. Proposition:
-- ---------------
--
-- map f (ys ++ zs) = map f ys ++ map f zs
--
--
-- Proof By Structural Induction:
-- ------------------------------
--
--
-- 1. Induction Beginning (1. I.B.):
-- ---------------------------------
--
--
-- (Base case 1.) :<=> ys := []
--
-- => (left) := map f (ys ++ zs)
-- | (Base case 1.)
-- = map f ([] ++ zs)
-- | ++
-- = map f zs
--
--
-- (right) := map f ys ++ map f zs
-- | (Base case 1.)
-- = map f [] ++ map f zs
-- | map
-- = map f zs
--
--
-- => (left) = (right)
--
-- ?
--
--
-- 1. Induction Hypothesis (1. I.H.):
-- ----------------------------------
--
-- For an arbitrary, but fixed list "ys", the statement ...
--
-- map f (ys ++ zs) = map f ys ++ map f zs
--
-- ... holds.
--
--
-- 1. Induction Step (1. I.S.):
-- ----------------------------
--
--
-- (left) := map f ( (y : ys) ++ zs )
-- | ++
-- = map f ( y : ( ys ++ zs ) )
-- | map
-- = f y : map f ( ys ++ zs )
-- | (1. I.H.)
-- = f y : map f ys ++ map f zs
-- | map
-- = map f (y : ys) ++ map f zs
--
--
-- (right) := map f (y : ys) ++ map f zs
--
--
-- => (left) = (right)
--
--
-- ??? (1. Proof)
But in this 'proof attempt' only "ys" was considered (1. I.H.).
What do I miss?
Pascal
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 78, Issue 11
*****************************************