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: OpenGLRaw Tutorial (Michael Baker)
2. Writing a custom pop function for a stack data type (doaltan)
3. Suspend/resume computation using Cont monad and callCC
(Dmitriy Matrosov)
4. Re: Writing a custom pop function for a stack data type
(divyanshu ranjan)
----------------------------------------------------------------------
Message: 1
Date: Mon, 11 Mar 2013 13:19:50 -0500
From: Michael Baker <[email protected]>
Subject: Re: [Haskell-beginners] OpenGLRaw Tutorial
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Message-ID:
<CACwW0UZ3UU106EcAk_s6DKsSbm4r8aE4O-DkdpCA7XYU=a2...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
Excellent Isaac, thanks!
On Mon, Mar 11, 2013 at 12:37 PM, Isaac Dupree <
[email protected]> wrote:
> On 03/11/2013 11:41 AM, Michael Baker wrote:
>
>> The concern that lead me to try OpenGLRaw
>> instead is that drawing every vertex/color/etc with a separate function
>> call seems incredibly inefficient. I imagine I'm going to have to learn
>> to use buffers at some point.
>>
>
> You are correct. Partly for that reason, glBegin()/glEnd()/glVertex*()
> don't even exist in OpenGL ES and are deprecated since OpenGL 3.0. It's a
> shame that so many OpenGL tutorials still teach them.
>
> Note to others: your program depends on glfw-b (or anyway, Hackage
> 'glfw-b' works and Hackage 'glfw' doesn't).
>
> glEnableVertexAttribArray/**glVertexAttribPointer are for passing data to
> shader programs, I believe. Everyone should use shader programs (GLSL).
> GL without shader programs uses the "fixed-function pipeline" which is
> deprecated. But I haven't used shaders yet, so I've attached how to do it
> with VBOs and the fixed-function pipeline. I used glInterleavedArrays and
> glDrawArrays. (That's probably not the only way to do it; OpenGL has lots
> of legacy and semi-redundant functions.)
>
> As jean verdier noted, your byte count argument to glBufferData was wrong;
> "fromIntegral $ length verticies * sizeOf (head verticies)" fixes it.
>
> Four coordinates per vertex is (as far as I know) not very useful for
> two-dimensional or three-dimensional shapes.
>
> Doing glGenBuffers every frame without glDeleteBuffers leaks buffers.
> Either save them or delete them. I didn't fix this. Control.Exception's
> bracket or bracket_ can be useful for this sort of thing.
>
> I also attached a version that can attach a color to each vertex. Haskell
> FFI peeps, is there a better way to do this than writing a Storable
> instance for each GL buffer data layout?
>
> -Isaac (who has been learning modern OpenGL for http://www.lasercake.net/)
>
>
> _______________________________________________
> 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/20130311/022c20e3/attachment-0001.htm>
------------------------------
Message: 2
Date: Tue, 12 Mar 2013 10:42:13 +0000 (GMT)
From: doaltan <[email protected]>
Subject: [Haskell-beginners] Writing a custom pop function for a stack
data type
To: "[email protected]" <[email protected]>
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Hi I have such a stack data structure:?
datamystack =Empty |Elem Char mystack derivingShow
I'm trying to get the head of the stack using this:
pophead :: Stack -> Char
pophead Empty = Empty
pophead (Element x stack) = x
And I'm getting this error for the last sentence of the function :
Not in scope: data constructor `Stack'
Can you tell me how to fix it?
Thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20130312/f641b3e4/attachment-0001.htm>
------------------------------
Message: 3
Date: Tue, 12 Mar 2013 14:50:17 +0400
From: Dmitriy Matrosov <[email protected]>
Subject: [Haskell-beginners] Suspend/resume computation using Cont
monad and callCC
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=US-ASCII
Hi.
I have two functions f and g, and i want them to execute in following
order: first function f runs, then suspends and passes control to
function g. Function g runs, then suspends and "unpauses" function f.
Function f finishes and passes control to function g, which also
finishes. Here is illustration ('o' means start of function, dot means
suspend and pass control to other function, 'x' means end of function):
f g
o
f-1 |
v
.-->o
| g-1
v
.<--.
|
f-2 v
x-->.
| g-2
v
<----------x
(to caller)
I want to implement this using Cont monad and callCC. And here is my
implementation:
import Data.Monoid
import Control.Monad.Cont
import Control.Monad.Writer
type M r = Cont r
fM :: M r [String]
fM = do
let xs' = "I'm in f-1" : []
(ys, k') <- callCC (gM xs')
let ys' = "I'm in f-2" : ys
zs <- k' ys'
let zs' = "I'm in f-3" : zs
return zs'
gM :: [String]
-> (([String], [String] -> M r [String]) -> M r [String])
-> M r ([String], [String] -> M r [String])
gM xs k = do
let xs' = "I'm in g-1" : xs
ys <- callCC (curry k xs')
let ys' = "I'm in g-2" : ys
return (ys', \_ -> return ys')
type T r = ContT r (Writer String)
fT :: T r ()
fT = do
lift $ tell "I'm in f-1\n"
k' <- callCC gT
lift $ tell "I'm in f-2\n"
k' undefined
lift $ tell "I'm in f-3\n"
gT :: ((() -> T r ()) -> T r ()) -> T r (() -> T r ())
gT k = do
lift $ tell "I'm in g-1\n"
callCC k
lift $ tell "I'm in g-2\n"
return (\_ -> return ())
First pair (fM and gM) uses monad result to track execution order,
second pair (fT and gT) uses Writer monad. But the tracks produced by
these pairs differ:
*Main> runCont fM id
["I'm in f-3","I'm in g-2","I'm in f-2","I'm in g-1","I'm in f-1"]
*Main> putStr . snd . runWriter . flip runContT return $ fT
I'm in f-1
I'm in g-1
I'm in f-2
I'm in g-2
I'm in f-2 <----- Why am i here?
I'm in f-3
fM/gM pair produces exactly the track, which i expect (see illustration
above, though 'f-3' section does not shown there). But fT/gT pair after
'g-2' section returns to "before f-2" point in function f. And i don't
understand why.
Thus, my question is why does fT/gT work so? And why do results from these
pairs differ?
--
Dmitriy Matrosov
------------------------------
Message: 4
Date: Tue, 12 Mar 2013 16:23:43 +0530
From: divyanshu ranjan <[email protected]>
Subject: Re: [Haskell-beginners] Writing a custom pop function for a
stack data type
To: doaltan <[email protected]>, The Haskell-Beginners Mailing List
- Discussion of primarily beginner-level topics related to Haskell
<[email protected]>
Message-ID:
<CAL9hw273DYXXBVitcRmGJtkOtBLR9=mzqif3161tzjk4xbk...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
You have declared new data type mystack not Stack, so haskell compiler
could not find Stack data type and its constructors. Secondly data type in
Haskell need to be start with capital letters like
data Mystack = Empty | Elem Char Mystack deriving Show
then correct Function definition is
pophead :: Mystack -> Char
Regards
Divyanshu
On Tue, Mar 12, 2013 at 4:12 PM, doaltan <[email protected]> wrote:
> Hi I have such a stack data structure:
>
> data mystack = Empty | Elem Char mystack deriving Show
>
> I'm trying to get the head of the stack using this:
> pophead :: Stack -> Char
> pophead Empty = Empty
> pophead (Element x stack) = x
> And I'm getting this error for the last sentence of the function :
>
> Not in
> scope: data constructor `Stack'
> Can you tell me how to fix it?
> Thanks.
>
>
> _______________________________________________
> 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/20130312/5f1c9cbd/attachment-0001.htm>
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 57, Issue 17
*****************************************