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: Conciseness question (Manfred Lotz)
2. Re: Conciseness question (David Place)
3. Re: haddock instance documentation (Antoine Latter)
4. Re: Conciseness question (Manfred Lotz)
5. Re: Conciseness question (David Place)
6. Show for Parameterized Type (Hartmut)
7. Re: Show for Parameterized Type (David Place)
8. Re: Show for Parameterized Type (Hartmut)
9. Re: Show for Parameterized Type (David Place)
----------------------------------------------------------------------
Message: 1
Date: Sun, 7 Aug 2011 19:09:36 +0200
From: Manfred Lotz <[email protected]>
Subject: Re: [Haskell-beginners] Conciseness question
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=US-ASCII
On Sun, 7 Aug 2011 12:52:59 -0400
David Place <[email protected]> wrote:
> On Aug 7, 2011, at 12:36 PM, Manfred Lotz wrote:
>
> > because then I have to write names d1, ..., d15 two times in order
> > to get my definitions right. I'm looking for a more elegant way
> > doing this.
> >
> >
> > Hope this is a bit clearer what I'm after.
>
> Yes, thank you, that is quite clear. I think that is the best you
> can do in Haskell. I really don't see it as inelegant at all. You
> define the variables d1 through d15 and then dirList is a function of
> those definitions. You type d1 once for its definition and next for
> its use. You would like to combine the two activities? Something
> like this perhaps?
> dirLst = [d1 = "somedir", d15 = "otherdir"]
>
If this were possible that would be fine. When trying to compile this
however I get: parse error on input `='
--
Manfred
------------------------------
Message: 2
Date: Sun, 7 Aug 2011 13:23:05 -0400
From: David Place <[email protected]>
Subject: Re: [Haskell-beginners] Conciseness question
To: Manfred Lotz <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
On Aug 7, 2011, at 1:09 PM, Manfred Lotz wrote:
> If this were possible that would be fine. When trying to compile this
> however I get: parse error on input `='
Yes, this is not legal syntax. I gave it as example of what I understand that
you want. It is not possible in Haskell.
------------------------------
Message: 3
Date: Sun, 7 Aug 2011 12:40:06 -0500
From: Antoine Latter <[email protected]>
Subject: Re: [Haskell-beginners] haddock instance documentation
To: Christopher Howard <[email protected]>
Cc: Haskell Beginners <[email protected]>
Message-ID:
<CAKjSnQHihEBe9xWE94Ka4Os3jX_e8fs=8ekwrn+n27q-b-u...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8
On Sun, Aug 7, 2011 at 12:13 PM, Christopher Howard
<[email protected]> wrote:
>
> Sorry, a mistake in my syntax. I was under the impression that instance
> functions had to be explicitly exported in a module declaration. In other
> words, individual instance functions aren't supposed to be listed by the
> generated documentation anyway, just the fact that the new type is an
> instance of said class.
>
Yep, that's my understanding of how it works.
Take care,
Antoine
------------------------------
Message: 4
Date: Sun, 7 Aug 2011 21:55:58 +0200
From: Manfred Lotz <[email protected]>
Subject: Re: [Haskell-beginners] Conciseness question
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=US-ASCII
On Sun, 7 Aug 2011 18:55:37 +0200
Ertugrul Soeylemez <[email protected]> wrote:
Thanks a lot for your suggestions.
>
> This is possible in Haskell using the mapM_ function, but it doesn't
> really solve your problem. What you need is a foldable data
> structure, which gives its entries names. As suggested earlier,
> Data.Map gives you such a structure. You can define a custom index
> type like this:
>
> data AppDir
> = ConfigAppDir
> | DataAppDir
> | OtherAppDir
> deriving Ord
>
> Then you can create a map from AppDir to a string:
>
> import Data.Map (Map)
>
> type AppDirs = Map AppDir FilePath
>
> This is a foldable data structure. Instead of mapM_ from the Prelude
> you can now use mapM_ or forM_ from Data.Foldable. To access
> individual directories you can either use safe lookups or unsafe
> lookups:
>
> import Data.Map (Map, (!), lookup)
>
> lookup ConfigAppDir myDirs
> myDirs ! ConfigAppDir
>
This is the solution I like. I have to accept that here I cannot reach
the conciseness of which might be due to Haskell being strongly typed.
> The former is the safe variant giving you a Maybe String, while the
> latter is the unsafe variant, which throws an exception, if the
> directory in question is not present.
>
Is the latter one really unsafe? I'm not quite sure how to code
something that the compiler accepts and crashes at runtime because
mydirs :: Map AppDir FilePath and I would believe that the compiler
would detect if the values after the ! is not from AppDir.
--
Manfred
------------------------------
Message: 5
Date: Sun, 7 Aug 2011 16:27:11 -0400
From: David Place <[email protected]>
Subject: Re: [Haskell-beginners] Conciseness question
To: Manfred Lotz <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
On Aug 7, 2011, at 3:55 PM, Manfred Lotz wrote:
>>
>> import Data.Map (Map, (!), lookup)
>>
>> lookup ConfigAppDir myDirs
>> myDirs ! ConfigAppDir
>>
>
> This is the solution I like. I have to accept that here I cannot reach
> the conciseness of which might be due to Haskell being strongly typed.
In your original note, you mentioned that you have a small number of entries in
your list of directories. If so, you might find that association lists work
just fine for you without needing to import Data.Map.
> http://hackage.haskell.org/packages/archive/base/latest/doc/html/Prelude.html#v:lookup
------------------------------
Message: 6
Date: Sun, 7 Aug 2011 23:39:02 +0200
From: Hartmut <[email protected]>
Subject: [Haskell-beginners] Show for Parameterized Type
To: [email protected]
Message-ID:
<CAFz=tHHKb=bgzoepk76qavpeb8v1nqbh8nuq6qrjxn36rsj...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
Hello,
I made a parameterized data type EW, which builds on a type of class Read
and Show.
When showing EW's it shall prefix the output with "EW:".
data (Read a,Show a) => EW a = EW a
x01 = EW 20
x02 = EW "Test"
instance Show (EW a) where
show (EW x) = show "EW:" ++ show x
But I got a syntax error with this above at "show (EW x) = ...":
No instance of (Read a) asrising a use of 'EW' in the pattern ....
How can I formulate this show method correctly?
I'd appreciate Your help
Hartmut
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20110807/94906f41/attachment-0001.htm>
------------------------------
Message: 7
Date: Sun, 7 Aug 2011 17:47:38 -0400
From: David Place <[email protected]>
Subject: Re: [Haskell-beginners] Show for Parameterized Type
To: Hartmut <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"
On Aug 7, 2011, at 5:39 PM, Hartmut wrote:
> How can I formulate this show method correctly?
instance (Show a, Read a) => Show (EW a) where
show (EW x) = show "EW:" ++ show x
____________________
David Place
Owner, Panpipes Ho! LLC
http://panpipesho.com
[email protected]
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20110807/346f0528/attachment-0001.htm>
------------------------------
Message: 8
Date: Sun, 7 Aug 2011 23:54:22 +0200
From: Hartmut <[email protected]>
Subject: Re: [Haskell-beginners] Show for Parameterized Type
To: David Place <[email protected]>
Cc: [email protected]
Message-ID:
<CAFz=tHHOZr-duso43TmHT9MZnRRkv-dDdLzEoQ=jjpplyja...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
David,
that was fast :-) Thank you for your help!
Hartmut
On Sun, Aug 7, 2011 at 11:47 PM, David Place <[email protected]> wrote:
> On Aug 7, 2011, at 5:39 PM, Hartmut wrote:
>
> How can I formulate this show method correctly?
>
>
> instance (Show a, Read a) => Show (EW a) where
> show (EW x) = show "EW:" ++ show x
>
>
> ____________________
> David Place
> Owner, Panpipes Ho! LLC
> http://panpipesho.com
> [email protected]
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20110807/426a0659/attachment-0001.htm>
------------------------------
Message: 9
Date: Sun, 7 Aug 2011 18:02:19 -0400
From: David Place <[email protected]>
Subject: Re: [Haskell-beginners] Show for Parameterized Type
To: Hartmut <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"
On Aug 7, 2011, at 5:54 PM, Hartmut wrote:
> David,
> that was fast :-) Thank you for your help!
> Hartmut
Your welcome. ;-) I needed the break from what I was doing. I think I
actually would like to add that normally i wouldn't put the class constraints
in the data type definition.
module Main where
data EW a = EW a
x01 = EW 20
x02 = EW "Test"
instance (Show a) => Show (EW a) where
show (EW x) = show "EW:" ++ show x
instance (Read a) => Read (EW a) where
read (etc...)
____________________
David Place
Owner, Panpipes Ho! LLC
http://panpipesho.com
[email protected]
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20110807/f40ea67e/attachment.htm>
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 38, Issue 14
*****************************************