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 (David Place)
2. Re: Conciseness question (Hein Hundal)
3. Where to put an experimental package? (.)
4. Re: Where to put an experimental package? (Tim Perry)
5. Re: Conciseness question (Manfred Lotz)
6. Re: Conciseness question (Brandon Allbery)
7. Re: Conciseness question (David Place)
8. Re: Conciseness question (Ertugrul Soeylemez)
9. Re: haddock instance documentation (Christopher Howard)
----------------------------------------------------------------------
Message: 1
Date: Sun, 7 Aug 2011 11:19:21 -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 11:07 AM, Manfred Lotz wrote:
>
> What I don't want to do is to write a definition like valList
> because if I add a new value I have to remind myself not to forget to
> add it to valList too.
Hi, Manfred.
I think we are having difficulty understanding what you are try to do. Since,
you are worried about conciseness, why not write out the Haskell program that
shows what you want to do without worrying about conciseness. Then we can look
for opportunities to improve it.
____________________
David Place
Owner, Panpipes Ho! LLC
http://panpipesho.com
[email protected]
------------------------------
Message: 2
Date: Sun, 7 Aug 2011 09:00:13 -0700 (PDT)
From: Hein Hundal <[email protected]>
Subject: Re: [Haskell-beginners] Conciseness question
To: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=iso-8859-1
Manfred Wrote:
> Hmm, not quite sure I'm understanding why Data.Map would
> help.
>
> What I want to have is something like the following without
> the
> verboseness of it:
>
> -- this is a minimal example.
> -- Assume I would have some 15 such values.
> a = "bla"
> b = "bla2"
>
> valList = [ a, b ]
>
> Now in my program on the one hand I want to do something
> with all
> values, thus:? map doSomething valList
>
> On the other hand I frequently want use single values in my
> program,
> like e.g.:
> ???let x =? "suffix " ++ a
>
>
> What I don't want to do is to write a definition like
> valList
> because if I add a new value I have to remind myself not to
> forget to
> add it to valList too.
Hi Manfred,
I think that the Map type is about the best you are going to get. (I am a
beginner, so take my advice with a few grains of salt.)
Here is some code that does something like what you want.
-- Start Code
import Data.Map as M
-- Makes a Map
m1 = M.fromList [('a', "bla"), ('b', "bla2"), ('c', "bla3")]
-- Function for looking up values in m1
look c = M.findWithDefault "fail" c m1
valList = M.keys m1
showSuffix = "suffix " ++ look 'a'
-- Add three ! to the end of every string in m1
m2 = fmap ( ++"!!!") m1
-- Add a new key-value pair
m3 = M.insert 'd' "blabla" m2
-- End Start Code
Cheers,
Hein
------------------------------
Message: 3
Date: Sun, 07 Aug 2011 18:04:32 +0200
From: "." <[email protected]>
Subject: [Haskell-beginners] Where to put an experimental package?
To: [email protected]
Message-ID: <1312733072.4020.3.camel@eddy>
Content-Type: text/plain; charset="UTF-8"
Hi all,
I have written a small module with some basic algorithms for
graphical models. I intend this for experimentation
and want to extend it as I go.
It is probably not the most beautiful code, and most probably also
not the most efficient, but I also want to change that as I learn more.
Now .. if I wanted to put that online so maybe other interested people
can find it, where would you go to?
Is hackage a good place for such things? Or is hackage for more mature
projects only?
Thanks a lot,
Christian
------------------------------
Message: 4
Date: Sun, 7 Aug 2011 09:30:32 -0700
From: Tim Perry <[email protected]>
Subject: Re: [Haskell-beginners] Where to put an experimental package?
To: "[email protected]" <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
Github perhaps?
On Aug 7, 2011, at 9:04, "." <[email protected]> wrote:
> Hi all,
> I have written a small module with some basic algorithms for
> graphical models. I intend this for experimentation
> and want to extend it as I go.
> It is probably not the most beautiful code, and most probably also
> not the most efficient, but I also want to change that as I learn more.
>
> Now .. if I wanted to put that online so maybe other interested people
> can find it, where would you go to?
> Is hackage a good place for such things? Or is hackage for more mature
> projects only?
>
> Thanks a lot,
> Christian
>
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
------------------------------
Message: 5
Date: Sun, 7 Aug 2011 18:36:07 +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
Hi David,
On Sun, 7 Aug 2011 11:19:21 -0400
David Place <[email protected]> wrote:
> On Aug 7, 2011, at 11:07 AM, Manfred Lotz wrote:
>
> >
> > What I don't want to do is to write a definition like valList
> > because if I add a new value I have to remind myself not to forget
> > to add it to valList too.
>
>
> Hi, Manfred.
>
> I think we are having difficulty understanding what you are try to
> do. Since, you are worried about conciseness, why not write out the
> Haskell program that shows what you want to do without worrying about
> conciseness. Then we can look for opportunities to improve it.
>
You may be right. Here is what I want to do.
I have some 15 directories as Strings, where I want to do certain
actions like to create those directories, or doing some other things
to all of those directories.
For doing this something like this would be good (for the sake of
simplicity I do not write down all 15 entries)
dirLst = [ "somedir", "otherdir" ]
main = do
map makeDir dirLst
...
Later on in the program I would need those directorie names to create
(depending upon the context) new pathnames. Now something like this
would be good.
-- In my program instead of d1,...,d15
-- I use meaningful names of course.
d1 = "somedir"
...
d15 = "otherdir"
doSomething fls = do
let pathname = d1 ++ "/bin"
copyFiles2bin fls pathname
...
I would like to combine both approaches in a concise (from a typing
point of view) way. This I don't like
d1 = "somedir"
...
d15 = "otherdir"
dirLst = [ d1, d15]
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.
--
Thanks,
Manfred
------------------------------
Message: 6
Date: Sun, 7 Aug 2011 12:43:42 -0400
From: Brandon Allbery <[email protected]>
Subject: Re: [Haskell-beginners] Conciseness question
To: Manfred Lotz <[email protected]>
Cc: [email protected]
Message-ID:
<cakfcl4wrro0lcn5y8t7ad7mhv_geqtemqadbp6zb0mtmyoe...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
On Sun, Aug 7, 2011 at 07:25, Manfred Lotz <[email protected]> wrote:
> -- initialize empty table
> P = {}
>
> P.a = "bla1"
> P.b = "bla2"
>
> and so on.
>
> Now I can refer to each value by name, and I also can easily iterate
> over the table P.
>
This looks to me like one of the HList-based record systems. But that could
get you into hot water fairly quickly, as while the record/lens packages try
to cover up the ugliness, it's all based on some fairly complex type
hackery.
http://www.haskell.org/haskellwiki/Extensible_record is an overview of the
field.
--
brandon s allbery [email protected]
wandering unix systems administrator (available) (412) 475-9364 vm/sms
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20110807/48b9f5cc/attachment-0001.htm>
------------------------------
Message: 7
Date: Sun, 7 Aug 2011 12:52:59 -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 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"]
How would these variables be scoped?
____________________
David Place
Owner, Panpipes Ho! LLC
http://panpipesho.com
[email protected]
------------------------------
Message: 8
Date: Sun, 7 Aug 2011 18:55:37 +0200
From: Ertugrul Soeylemez <[email protected]>
Subject: Re: [Haskell-beginners] Conciseness question
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=US-ASCII
Manfred Lotz <[email protected]> wrote:
> I have some 15 directories as Strings, where I want to do certain
> actions like to create those directories, or doing some other things
> to all of those directories.
>
> For doing this something like this would be good (for the sake of
> simplicity I do not write down all 15 entries)
>
> dirLst = [ "somedir", "otherdir" ]
>
> main = do
> map makeDir dirLst
> ...
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
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.
Another possibility, though more verbose, but cleaner, is to define your
own data structure and define a Foldable instance for it:
data AppDirs a =
AppDirs {
configAppDir :: a,
dataAppDir :: a,
otherAppDir :: a
}
instance Foldable AppDirs where
foldr f dirs =
mconcat . map f . map ($ dirs) $
[configAppDir, dataAppDir, otherAppDir]
I think, the Map solution is cleaner.
Greets,
Ertugrul
--
nightmare = unsafePerformIO (getWrongWife >>= sex)
http://ertes.de/
------------------------------
Message: 9
Date: Sun, 07 Aug 2011 09:13:59 -0800
From: Christopher Howard <[email protected]>
Subject: Re: [Haskell-beginners] haddock instance documentation
To: Antoine Latter <[email protected]>, Haskell Beginners
<[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8; format=flowed
On 08/06/2011 11:37 PM, Antoine Latter wrote:
> On Sun, Aug 7, 2011 at 2:03 AM, Christopher Howard
> <[email protected]> wrote:
>> I'm learning to comment my code for haddock. However, haddock seems to be
>> ignoring my documentation comments for instance implementations. Instead, it
>> just uses the default explanation given in the original class definition.
>> Does this require some kind of special syntax?
>
> Can you give an example of what you are doing which doesn't do what
> you expect? I've had no trouble with this using Haddock 2.9.2.
>
> Antoine
>
>>
>> --
>> frigidcode.com
>> theologia.indicium.us
>>
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://www.haskell.org/mailman/listinfo/beginners
>>
>
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.
--
frigidcode.com
theologia.indicium.us
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 38, Issue 13
*****************************************