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: Data.Tree computation (Gabi)
2. Re: Re: Data.Tree computation (Stephen Tetley)
3. Re: consing an element to a list inside a file ([email protected])
4. Regular expressions in case (legajid)
5. Re: Regular expressions in case (Daniel Fischer)
6. Re: consing an element to a list inside a file (Daniel Fischer)
7. running HGL on Mac OSX (Vojt?ch Knyttl)
8. distinguished types (Rick Murphy)
9. Re: distinguished types (Felipe Lessa)
----------------------------------------------------------------------
Message: 1
Date: Fri, 12 Feb 2010 16:30:48 +0200
From: Gabi <[email protected]>
Subject: [Haskell-beginners] Re: Data.Tree computation
To: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
The reason I wanted to use Data.Tree instead of my own is that I hoped
to serliaze it using Data.Binary (which supposed to support Data.Tree)
Alas, It doesn't work. Need to figure it out yet..
*Main Data.Binary Data.Tree> :m +Data.Binary
*Main Data.Binary Data.Tree> encode aTree
<interactive>:1:0:
No instance for (Binary ANode)
arising from a use of `encode' at <interactive>:1:0-11
Possible fix: add an instance declaration for (Binary ANode)
In the expression: encode aTree
In the definition of `it': it = encode aTree
--
Regards,
Gabi
http://bugspy.net
------------------------------
Message: 2
Date: Fri, 12 Feb 2010 15:24:53 +0000
From: Stephen Tetley <[email protected]>
Subject: Re: [Haskell-beginners] Re: Data.Tree computation
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
Hello Gabi
The docs for Data.Binary use a binary tree as an example - see about
half way down the page...
http://hackage.haskell.org/packages/archive/binary/0.5.0.2/doc/html/Data-Binary.html
On 12 February 2010 14:30, Gabi <[email protected]> wrote:
> The reason I wanted to use Data.Tree instead of my own is that I hoped
> to serliaze it using Data.Binary (which supposed to support Data.Tree)
> Alas, It doesn't work. Need to figure it out yet..
>
------------------------------
Message: 3
Date: Fri, 12 Feb 2010 20:15:26 +0100
From: [email protected]
Subject: Re: [Haskell-beginners] consing an element to a list inside a
file
To: Daniel Fischer <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"
the exercise looks like that:
readMyCal :: IO MyCalendar
readMyCal = do putStr "day: "
d <- readInt
putStr "month: "
m <- readMonth
putStr "year: "
y <- readInt
let mydate = (d,m,y)
if not (legalDate mydate) then
do putStrLn "wrong"
--COMPLETE-1--
else
--COMPLETE-2--
COMPLETE-1: the user can give in a new date. I did it by simple calling the
function again
COMPLETE-2: the user can choose if he wants to enter a new. If not, all dates
the user has put in should be put out as a calendar (a list of dates)
-------- Original-Nachricht --------
> Datum: Thu, 11 Feb 2010 23:30:05 +0100
> Von: Daniel Fischer <[email protected]>
> An: [email protected]
> CC: [email protected]
> Betreff: Re: [Haskell-beginners] consing an element to a list inside a file
> Am Donnerstag 11 Februar 2010 23:04:01 schrieb [email protected]:
> > but the exercise was nearly complete on the sheet and I just have to
> > complete two parts and one of them is to ask the user if he want's to do
> > more input. If so, I have to let him input a new value (triple) for
> > MyDatatype, otherwise I have to print the list with all triples
> >
>
> But to print it, you need to have a reference to the list of inputs. The
> easiest way is to have it as a parameter in the worker loop.
>
> What *exactly* is your task? What is given and what are the specifications
> for a solution?
>
> > >
> > > Am Donnerstag 11 Februar 2010 22:34:45 schrieb [email protected]:
> > > > the problem is the function should be
> > > > readMyDatatype :: IO MyDatatype
> > > > readMyDatatype = do ...
> > > > Is it possible to do it somehow different without a parameter?
> > >
> > > Separate the worker from the API function.
> > >
> > > API:
> > >
> > > readMyDatatype :: IO MyDatatype
> > > readMyDatatype = call worker with appropriate arguments
> > >
> > > worker:
> > >
> > > readMD :: t1 -> t2 -> ... -> tn -> IO MyDatatype
--
Sicherer, schneller und einfacher. Die aktuellen Internet-Browser -
jetzt kostenlos herunterladen! http://portal.gmx.net/de/go/atbrowser
------------------------------
Message: 4
Date: Fri, 12 Feb 2010 22:05:57 +0100
From: legajid <[email protected]>
Subject: [Haskell-beginners] Regular expressions in case
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Hi,
is it possible to write regular expressions in case .. of ?
I tried it, with no success.
a x =
case x of
"a1" -> "A1"
"a2" -> "A2"
"a*" -> "A*"
"b1" -> "B1"
_ -> "_"
for x="a3", result is _, instead of A* that i wanted.
Thks,
Didier
------------------------------
Message: 5
Date: Fri, 12 Feb 2010 23:04:12 +0100
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] Regular expressions in case
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Am Freitag 12 Februar 2010 22:05:57 schrieb legajid:
> Hi,
> is it possible to write regular expressions in case .. of ?
>
> I tried it, with no success.
>
> a x =
> case x of
> "a1" -> "A1"
> "a2" -> "A2"
> "a*" -> "A*"
> "b1" -> "B1"
> _ -> "_"
>
>
> for x="a3", result is _, instead of A* that i wanted.
>
> Thks,
> Didier
No, case expressions use "pattern matching" as in
http://haskell.org/onlinereport/exps.html#sect3.17
, that is, matching on constructors, not "pattern matching" as in matching
a regex pattern. You can do a little like that with wildcard patterns,
a x =
case x of
"a1" -> "A1"
"a2" -> "A2"
('a':_) -> "A*"
"b1" -> "B1"
_ -> "_"
in a simple case like the above. In more complicated situations, use a mix
of pattern matching and guards,
import Text.Regex.PCRE
a' x =
case x of
"a1" -> "A1"
('a':rest)
| rest =~ "[0-9]*" -> optAGen
| cond1 rest -> opt1
| cond2 rest -> opt2
"b1" -> "B1"
blah
| blah =~ "[0-9]*" -> optNum
_ -> defaultOption
------------------------------
Message: 6
Date: Fri, 12 Feb 2010 23:18:06 +0100
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] consing an element to a list inside a
file
To: [email protected]
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Am Freitag 12 Februar 2010 20:15:26 schrieb [email protected]:
> the exercise looks like that:
>
> readMyCal :: IO MyCalendar
> readMyCal = do putStr "day: "
> d <- readInt
> putStr "month: "
> m <- readMonth
> putStr "year: "
> y <- readInt
> let mydate = (d,m,y)
> if not (legalDate mydate) then
> do putStrLn "wrong"
> --COMPLETE-1--
> else
> --COMPLETE-2--
>
> COMPLETE-1: the user can give in a new date. I did it by simple calling
> the function again
Reasonable.
> COMPLETE-2: the user can choose if he wants to enter
> a new. If not, all dates the user has put in should be put out as a
> calendar (a list of dates)
>
Okay, that's not nice. But since you have no global variables to store the
list of dates entered in (yes, there are ways to have global variables, but
it's not a good idea unless you really have to), call
readMoreDates :: [MyDate] -> IO MyCaledar
readMoreDates previous = do ...
(code duplication where it isn't really necessary, but what the heck).
------------------------------
Message: 7
Date: Sat, 13 Feb 2010 16:48:04 +0100
From: Vojt?ch Knyttl <[email protected]>
Subject: [Haskell-beginners] running HGL on Mac OSX
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=windows-1252
Hello,
I am having difficulties running HGL on Mac OSX, Snow Leopard. Here is what
I've done:
1. Installed X11 for OSX
("About" dialog says: The X Window System, XQuartz 2.3.4 (xorg-server
1.4.2-apple45))
2. Got X11 from Hackage configured, built and installed however, there
where quite a lot of warnings:
[ 8 of 25] Compiling Graphics.X11.Xlib.Color ( Graphics/X11/Xlib/Color.hs,
dist/build/Graphics/X11/Xlib/Color.o )
Graphics/X11/Xlib/Color.hs:38:0:
Warning: The import of `Foreign.C.Types' is redundant
except perhaps to import instances from `Foreign.C.Types'
To import instances alone, use: import Foreign.C.Types()
[ 9 of 25] Compiling Graphics.X11.Xlib.Font (
dist/build/Graphics/X11/Xlib/Font.hs, dist/build/Graphics/X11/Xlib/Font.o )
Graphics/X11/Xlib/Font.hsc:167:1:
Warning: A do-notation statement discarded a result of type CInt.
Suppress this warning by saying "_ <- xTextExtents
font_struct
c_string
(fromIntegral nchars)
direction_return
font_ascent_return
font_descent_return
overall_return",
or by using the flag -fno-warn-unused-do-bind
and so on.
3. Got HGL package, built and installed with some warnings like:
[ 1 of 27] Compiling Graphics.HGL.Internals.Flag (
Graphics/HGL/Internals/Flag.hs, dist/build/Graphics/HGL/Internals/Flag.o )
Graphics/HGL/Internals/Flag.hs:1:0:
Warning: Module `Prelude' is deprecated:
You are using the old package `base' version 3.x.
Future GHC versions will not support base version 3.x. You
should update your code to use the new base version 4.x.
Now, when I try to run simple program like:
main = runGraphics $
withWindow_ "Hello World Window" (300, 200) $ \ w -> do
drawInWindow w $ text (100, 100) "Hello World"
drawInWindow w $ ellipse (100, 80) (200, 180)
getKey w
it says:
$ ghci graphics.hs
GHCi, version 6.12.1: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading package ffi-1.0 ... linking ... done.
Ok, modules loaded: Main.
Prelude Main> main
Loading package syb-0.1.0.2 ... linking ... done.
Loading package X11-1.5.0.0 ... can't load .so/.DLL for: X11
(dlopen(libX11.dylib, 9): image not found)
Prelude Main>
Just to precise, I have X11 running (it can be seen in the OSX dock)
Thanks
------------------------------
Message: 8
Date: Sat, 13 Feb 2010 15:29:55 -0500
From: Rick Murphy <[email protected]>
Subject: [Haskell-beginners] distinguished types
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Greetings and thanks in advance for all the great work on this list.
Being new Haskell I hope someone could help me clarify the use of the
term *distinguished type* in relation to Haskell 98 as well as confirm
my understanding of the construction of a distinguished type in GHC.
I understand from [1] that a distinguised type is defined as a type with
only one non-bottom value and that value is in fact identical to the
name of the type. [1] provides the unit type () as an example of a
Haskell distinguished type.
Would it be accurate to say that an approach to creating distinguished
types in Haskell is to create data types with a single constructor whose
name is identical to the data type name?
More specifically, would
> data F = F deriving (Show)
create a distinguished type F in Haskell?
I've searched the Haskell Report, but there's no indication that the
report recognizes distinguished types. Is that true and if so why ?
1. http://okmij.org/ftp/Scheme/misc.html
--
Rick
cell: 703-201-9129
web: http://www.rickmurphy.org
blog: http://phaneron.rickmurphy.org
------------------------------
Message: 9
Date: Sat, 13 Feb 2010 19:03:20 -0200
From: Felipe Lessa <[email protected]>
Subject: Re: [Haskell-beginners] distinguished types
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
On Sat, Feb 13, 2010 at 03:29:55PM -0500, Rick Murphy wrote:
> I understand from [1] that a distinguised type is defined as a type
> with only one non-bottom value and that value is in fact identical
> to the name of the type. [1] provides the unit type () as an example
> of a Haskell distinguished type.
>
> Would it be accurate to say that an approach to creating
> distinguished types in Haskell is to create data types with a single
> constructor whose name is identical to the data type name?
Well, I don't have not even one milliOleg. That said, I think he
used "distinguished" to mean that it is a "curious" data type
included in the language. Maybe he also meant that, at least in
Haskell, the type may receive special notation (you can't say
'data () = ()').
HTH,
--
Felipe.
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 20, Issue 22
*****************************************