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. HDBC commit problem (Moritz Tacke)
2. Re: Wrapping random (Torsten Otto)
3. Re: Bit arithmetic in Haskell (Artyom Shalkhakov)
4. A type level programming question (Levi Stephen)
5. Re: [Haskell] Re: Help : A problem with IO (wman)
6. Existential data types (Michael Snoyman)
7. gtk2hs timeoutSeq (Norbert Wojtowicz)
8. Re: Existential data types (Brandon S. Allbery KF8NH)
----------------------------------------------------------------------
Message: 1
Date: Tue, 9 Dec 2008 14:58:14 +0100
From: "Moritz Tacke" <[email protected]>
Subject: [Haskell-beginners] HDBC commit problem
To: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
Hi!
I am running into problems while using HDBC with the sqlite3 backend.
The HDBC "commit" statement frequently results in exceptions with the
sqlite3 error code 1, "SQL logic error or no database". As far as I
know, and as far as the HDBC docs tell me, "commit" simply writes all
yet open transactions onto the disk. How can it fail? Given the
implicit opening of transactions as done by HDBC, a call to commit
should succeed in any situation (or am I wrong?).
The HDBC
documentation mentions the prepare- and execute-steps as the ones which
might throw exceptions - what are the problems a call to "commit"
might encounter? I do not suspect SQL errors to be the cause - those
should lead to earlier exceptions - and the database is definitly
present and opened, as select calls following the failing commit
statments succeed.
Greetings!
------------------------------
Message: 2
Date: Tue, 9 Dec 2008 15:35:01 +0100
From: Torsten Otto <[email protected]>
Subject: Re: [Haskell-beginners] Wrapping random
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes
Thanks a bunch for the replies, they were much appreciated. In the
meantime we talked in more depth than I had initially planned to about
randomness, statefulness and even monads to some extent.
(And the chatbot gives its random replies as was planned :-) )
Kind regards,
Torsten
------------------------------
Message: 3
Date: Wed, 10 Dec 2008 10:02:02 +0600
From: "Artyom Shalkhakov" <[email protected]>
Subject: [Haskell-beginners] Re: Bit arithmetic in Haskell
To: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=UTF-8
Hello,
It looks like I have some problems with math. Problem solved.
Regards,
Artyom Shalkhakov.
------------------------------
Message: 4
Date: Mon, 15 Dec 2008 09:41:29 +1030
From: "Levi Stephen" <[email protected]>
Subject: [Haskell-beginners] A type level programming question
To: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
Hi,
I was looking at Data.Param.FSVec from parameterized-data [1].
The method to retrieve an element from a FSVec has the following type:
(!) :: (Pos s, Nat i, i :<: s) => FSVec s a -> i -> a
I was wondering if it was possible to write a function of type:
elementAt :: FSVec s a -> Int -> a
that called the above function, throwing an error if the index was out
of bounds. e.g.,
elementAt v idx | idx < 0 || idx > length v = error "Out of bounds"
| otherwise = ....
But, I can't figure out how to implement the otherwise part. In
particular I can't work out how to call the (!) function with the i
:<: s class constraint satisfied.
Thanks,
Levi
------------------------------
Message: 5
Date: Mon, 15 Dec 2008 11:35:24 +0100
From: wman <[email protected]>
Subject: [Haskell-beginners] Re: [Haskell] Re: Help : A problem with
IO
To: "abdullah abdul Khadir" <[email protected]>
Cc: [email protected], [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
you probably got it pointed out in haskell-beginners, but in case not:
On Thu, Nov 27, 2008 at 7:10 PM, abdullah abdul Khadir <
[email protected]> wrote:
> a) I need to put a do after else for more than one instruction (?)
No, the do thingy is a syntactic sugar for chaining "warm, fuzzy" (the
"preffered" wannabe-joke-term for the presumably scary term monads/monadic)
operations.
it allows you to write in "classical" imperative/sequential style instead of
chaining operations manually (using the >> and >>= operators, which the do
notation translates into anyway). lookup some monad tutorials/docs.
you are right in that if there is only one operation, no transformation is
needed, so the do is unnecessary.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20081215/cb2fd47b/attachment-0001.htm
------------------------------
Message: 6
Date: Mon, 15 Dec 2008 09:49:38 -0800
From: "Michael Snoyman" <[email protected]>
Subject: [Haskell-beginners] Existential data types
To: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="utf-8"
Hi everyone,
I believe I have come to the conclusion that what I would like to do is
impossible, but I would like to have that confirmed. I would basically like
to be able to have a heterogeneous list without boxing everything in a data
type. Below is the sample code, with the code I would like to use commented
out. I'm I missing something, or does Haskell simply not support what I am
trying for?
{-# LANGUAGE ExistentialQuantification #-}
data Foo = Foo String
class IFoo a where
toFoo :: a -> Foo
instance IFoo Foo where
toFoo = id
data A = A String
instance IFoo A where
toFoo (A a) = Foo a
data B = B Int
instance IFoo B where
toFoo (B b) = Foo $ show b
data FooBox = forall t. IFoo t => FooBox t
instance IFoo FooBox where
toFoo (FooBox f) = toFoo f
myPrint :: IFoo t => [(String, t)] -> IO ()
myPrint = mapM_ myPrint'
myPrint' :: IFoo t => (String, t) -> IO ()
myPrint' (key, value) =
let (Foo foo) = toFoo value
in putStrLn $ key ++ ": " ++ foo
{- What I'd like to do:
main = myPrint
[ ("one", Foo "1")
, ("two", A "2")
]
-}
main = myPrint
[ ("one", FooBox $ Foo "1")
, ("two", FooBox $ A "2")
]
----
Thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20081215/05e6c5ee/attachment-0001.htm
------------------------------
Message: 7
Date: Mon, 15 Dec 2008 20:02:31 +0100
From: "Norbert Wojtowicz" <[email protected]>
Subject: [Haskell-beginners] gtk2hs timeoutSeq
To: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
Hello,
I'm trying to use a sequence of timeoutAdd's in a gtk2hs app. By
sequence, I mean one (IO Bool) must return as False before the next
begins:
timeoutSeq [ (fn1, 100), (fn2, 200) ]
fn1 will keep running every 100, until it returns False. Then fn2 will
get a timeoutAdd 200, and so on...
First attempt (works fine, I think):
timeoutSeq :: [(IO Bool, Int)] -> IO ()
timeoutSeq [] = return ()
timeoutSeq ((fn,n):rest) = do
timeoutAdd (aux fn rest) n
return ()
where
aux :: IO Bool -> [(IO Bool, Int)] -> IO Bool
aux fn [] = fn
aux fn lst = do
r <- fn
case r of
True -> return True
False -> do
timeoutSeq lst
return False
Now, I'd like to write a timeoutDep (fn1, n1) (fn2, n2) where fn1 and
fn2 are both running at their respective rates, and fn1 will run only
as long as fn2 is running. The use case for this is eg: Run fn1 often
and fn2 less often, but I only care fn1 to be running as long as fn2
is still valid.
timeoutDep (fn,n) (fn2,n2) = do
hdl <- timeoutAdd fn n
timeoutSeq [(aux fn2 hdl, n2), (return False, 100)]
where
aux fn2 hdl = do
r <- fn2
case r of
True -> return True
False -> do
timeoutRemove hdl
return False
This implementation sort of works, except it exits immiediately (and
as IO ()), so I can't for example do this:
timeoutSeq [((timeoutDep (print "a" >> return True, 100)
(print "b" >> return
True, 100)), 100)
, (print "c" >> return False, 100)]
Ths silly example should keep printing 'a' and 'b' w/o ever printing
'c'. Any ideas or suggestions?
------------------------------
Message: 8
Date: Mon, 15 Dec 2008 14:55:35 -0500
From: "Brandon S. Allbery KF8NH" <[email protected]>
Subject: Re: [Haskell-beginners] Existential data types
To: "Michael Snoyman" <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"
On 2008 Dec 15, at 12:49, Michael Snoyman wrote:
> I believe I have come to the conclusion that what I would like to do
> is impossible, but I would like to have that confirmed. I would
> basically like to be able to have a heterogeneous list without
> boxing everything in a data type. Below is the sample code, with the
> code I would like to use commented out. I'm I missing something, or
> does Haskell simply not support what I am trying for?
It's possible but nontrivial. Look at HList on http://hackage.haskell.org
for an implementation.
--
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] [email protected]
system administrator [openafs,heimdal,too many hats] [email protected]
electrical and computer engineering, carnegie mellon university KF8NH
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20081215/3468c257/attachment.htm
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 6, Issue 4
***************************************