Re: [Haskell-cafe] Creating a dependency graph (in the hope it may show some structure)

2012-05-02 Thread Bram Neijt
Thank you!

I feel stupid for posting a question when there is already a stackoverflow
answer. But now that I have that, I have all the information I need.

Greets,

Bram
 On May 2, 2012 12:49 AM, Ivan Lazar Miljenovic ivan.miljeno...@gmail.com
wrote:

 On 2 May 2012 06:15, Bram Neijt bne...@gmail.com wrote:
  Dear Haskelllers,
 
  I've reacently started with Haskell and during the Dutch Hackaton[3],
  I decided to generate graphs of dependencies. I was thinking about
  doing this for Java earlier, and that weekend I decided to write the
  tooling in Haskell.

 Just to be clear, what are you referring to by dependencies:

 * Package dependencies

 * Inter-module dependencies

 * Call-graph dependencies

 And are you doing this on a per-module or a per-package basis?

 
  I've written two programs: hs2dot[1] and dotimate[2]. The first
  generates a dot file (Graphviz) from all .hs files below the current
  working directory. The second will take one or more dot files and call
  neato (from Graphviz) multiple times to generate frames of neato
  output from one to the next.
 
  Trying hs2dot and dotimate on two sequencial commits in the
  cabal/cabal-install/frames directory already gives me a way to complex
  and full graph. See attached.
 
  == My question is: What dependencies, if any, would be nice to graph,
  and/or which dependencies could I filter out to keep this from
  becoming a mess?

 First of all, consider this list of existing graph-based visualisation
 tools for Haskell and see if any have some features you can duplicate:

 http://stackoverflow.com/questions/7427094/generate-diagrams-for-haskell-code

 I know in SourceGraph, my take was to try and do different kinds of
 pruning, collapsing, etc. to shrink the information overload down
 (however, I haven't touched SourceGraph apart from dependency updates
 for quite a while).

 
  Greetings,
 
  Bram Neijt
 
  [1] https://gist.github.com/bneijt/hs2dot
  [2] https://gist.github.com/bneijt/dotimate
  [3] http://www.haskell.org/haskellwiki/DHD_UHac#Utrecht_Hackathon
 
  ___
  Haskell-Cafe mailing list
  Haskell-Cafe@haskell.org
  http://www.haskell.org/mailman/listinfo/haskell-cafe
 



 --
 Ivan Lazar Miljenovic
 ivan.miljeno...@gmail.com
 http://IvanMiljenovic.wordpress.com

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] heterogeneous environment

2012-05-02 Thread Ben
dear static typing masters --

while working on an STM-like library, i ran into the issue of trying to create 
a transaction log for reads / writes of heterogeneous reference types.  i don't 
have a good answer to this problem.  the problem is twofold : first, the 
general heterogeneous collection problem, and second, connecting a reference to 
it's log.  there are some solutions i've tried but each has drawbacks :

- store the transaction log inside of the reference itself.  essentially, each 
reference has an IORef (Map ThreadId a) associated to it.  this is the approach 
used by [1].  unfortunately this creates a point of concurrency contention at 
each reference for each read / write, and a lot of repeated computation (the 
transaction log is spread out in a lot of pieces.) 

- use Data.Unique to identify Refs, and use existential quantification or 
Data.Dynamic to create a heterogenous Map from uid to log.  for example, to 
represent a log of compare-and-swaps we might do something like

data Ref a = Ref (IORef a) Unique
data OpaqueCAS = forall a . OpaqueCAS { casRef :: Ref a, oldVal :: a, newVal :: 
a }
type CASLog = Map Unique OpaqueCAS
logCAS r@(Ref _ uid) o n log = insert uid (OpaqueCAS r o n) log...

but what if the transaction wants to perform a second CAS on a reference we've 
already CAS'd?  then we should create a combined OpaqueCAS record which expects 
the first oldVal and swaps in the second newVal.  unfortunately the type 
checker balks at this, as it can't prove that the type variable 'a from the 
first record is the same as the 'a in the new record; i suppose there might be 
some fancy type shenanigans which might solve this...

Data.Dynamic works but puts a Typeable constraint on the Ref type, so requires 
the user to modify their data types, and requires a run-time type check (and 
while performance isn't paramount now it will become important to me later.)  
also it doesn't feel right...

- tupling and functional representations.  a monadic function that does a read 
on an reference can be thought of as a pure function with an extra argument.  a 
monadic function that does a write can be thought of as a pure function with an 
extra return value.  combining all the reads and writes into a transaction log 
is a big network / switchboard connecting problem, e.g. creating the extra 
inputs / outputs to the various functions and then stitching them together.  
running the monad then just is connecting up the final composed function to the 
actual input / output references.  in a sense this amounts to tupling (or 
currying) the heterogeneous types.  (is this is a kind of final 
representation, in the finally tagless sense?)

i looked at this there were two problems : 1 - the representation is very 
difficult to manipulate, at least the way i was trying (using the arrow 
operations); the switchboard problem is extremely verbose, and 2 - it is hard 
to reconcile identity and position in the tuples -- the repeated read / write 
problem again.  i also experimented with HList but got stuck on similar issues.

it strikes me this is just the problem of keeping an environment for an 
interpreter of a language with mutable heterogeneous reference types.  this 
must be a problem that has either been solved or else there is a haskell point 
of view on it i'm not grasping which avoids the need for this data structure.  
maybe there is a way of writing this as an interpreter or using some existing 
monad, like the ST monad?

best, ben

[1] - Frank Huch and Frank Kupke, A High-Level Implementation of Composable 
Memory Transactions in Concurrent Haskell


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Again, version conflicting problem with cabal-install

2012-05-02 Thread Magicloud Magiclouds
Hi, long time no see.
I am using cabal-install-0.15.0. And the new solver. It sure solves
some problem. Thanks for the work.
Well, on the other hand, there still are hackages that I just have no
idea how the author make it (probably not up-to-date hackage
database). After human-solver checking, these hackages are not be able
to build at all under certain conditions.
So, I am voting on the force-allow flag.

On Sat, Feb 4, 2012 at 12:36 AM, Andres Löh andres.l...@googlemail.com wrote:
 Hi.

  --force-allow=foo-1.3

 with the semantics that all dependencies on foo will be changed to
 allow foo-1.3 to be chosen. Would that be ok? Other suggestions?

 Can't this be integrated with the current --constraint flag?

 It could be, but ...

 If the
 constraint is able to be satisfied without unrestricting any bounds,
 fine.  Otherwise, unrestrict any bounds on that constraint.  What
 would be the drawbacks?

 ... it shouldn't happen automatically. There are perfectly valid and
 safe reasons to use --constraint, whereas this new feature is
 inherently unsafe. But allowing general constraint syntax and calling
 the flag something with constraint in it is perhaps a good idea.

 An advantage is being able to specify --constraint='foo = 1.3' to get
 foo-1.3.7.2 instead of having to find out exactly which version you
 want.  And if you already know what you want, you may always say
 --constraint='foo == 1.3.7.2'.

 Yes.

 Looking forward to the new solver! =)

 I need testers and feedback. You can already use it. It's in the
 cabal-install development version, and can be enabled by saying
 --solver=modular on the command line.

 Cheers,
  Andres



-- 
竹密岂妨流水过
山高哪阻野云飞

And for G+, please use magiclouds#gmail.com.

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Reader monad, refactoring and missing the point all at once

2012-05-02 Thread Eugene Dzhurinsky
Hi all!

Last day I was trying to fix idiii library, because it uses utf8 for parsing
non-unicode content. I found the functions

 -- | Parses one value and returns it as a 'String'
 parseString :: CharEncoding - TagParser String
 parseString enc = do
 v - case enc of
   0x01 - parseUntilWord16Null -- UTF-16
   0x02 - parseUntilWord16Null -- UTF-16 BOM
   _- parseUntilWord8Null  -- ISO-8859-1 or UTF-8
 return $ encPack enc v
 
 encPack :: CharEncoding - [Token] - String
 encPack 0x00s  = Text.unpack $ decodeASCII   $ BS.pack s
 encPack 0x01 (0xFF:0xFE:s) = Text.unpack $ decodeUtf16LE $ BS.pack s
 encPack 0x01 (0xFE:0xFF:s) = Text.unpack $ decodeUtf16BE $ BS.pack s
 encPack 0x02s  = Text.unpack $ decodeUtf16BE $ BS.pack s
 encPack _   s  = Text.unpack $ decodeUtf8$ BS.pack s

updated the dependency from 
 import Data.Text.Encoding (decodeASCII, decodeUtf16LE, decodeUtf16BE, 
 decodeUtf8)
to
 import Data.Text.ICU.Convert

and added implementation for decoding functions:

 decodeAny :: String - BS.ByteString - Text.Text
 decodeAny charset src = unsafePerformIO $ ((flip toUnicode) src) `fmap` open 
 charset (Just True)

 decodeASCII :: BS.ByteString - Text.Text
 decodeASCII = decodeAny latin1
 
 decodeUtf16LE = decodeAny utf-16le
 
 decodeUtf16BE = decodeAny utf-16be
 
 decodeUtf8 = decodeAny utf-8

Now I want to add possibility to specify encoding to yse with decodeASCII. I 
was 
thinking of adding Reader monad and providing some sort of charset
configuration there - but it will lead up to complicating the code, which uses
this parseString function. And this code is used inside Parser of 
Text.ParserCombinators.Poly.State - 
so I will need to update all usages of this parser.

Another approach might be to use IORef with encoding stored there, but I
don't really like this solution.

What would be the best way of refactoring of such kind?

Thanks!

-- 
Eugene N Dzhurinsky


pgp9sNFLGUKtm.pgp
Description: PGP signature
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Learn you

2012-05-02 Thread 山本和彦
Hello cafe,

Translating Learn You a Haskell for Great Good into Japanese was
finished and will be published on 22 May. I guess it's worth watching
its cover page:


http://www.amazon.co.jp/%E3%81%99%E3%81%94%E3%81%84Haskell%E3%81%9F%E3%81%AE%E3%81%97%E3%81%8F%E5%AD%A6%E3%81%BC%E3%81%86-Miran-Lipova%C4%8Da/dp/4274068854

There are two translators: Tanaka is the author of peggy and Muranushi is
the author of Monadius.

Regards,

--Kazu

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] twitter election on favorite programming language

2012-05-02 Thread 山本和彦
Hello Leon,

 Out of curiousity,  was this a plurality election (vote for one),  or an
 approval election (vote for many)?

Vote for one.

This application requires twitter login.

--Kazu

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Haskell Hackathon in Munich

2012-05-02 Thread Simon Hengel
Hi Heinrich,

 the Munich Haskell Meeting is glad to announce a local one day
 Hackathon in Munich. It will take place the 12th of May 2012 from
 10am to 6pm. Please checkout the details at:

I'll join.

BTW: Any reason why we would not want to put this on the wiki?  And can
we create an IRC channel on freenode for that (#munihac, or anything)?

Cheers,
Simon

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] using ResourceT with MVars

2012-05-02 Thread Warren Harris
I would like to use LevelDB in my code, and the HEAD version of leveldb-haskell 
now uses runResourceT to manage open db connections and iterators. I would also 
like to run multiple threads, and coordinate them for transaction-like 
behavior, i.e. read and writing data without interruption. LevelDB doesn't 
support transactions itself, so the alternative would seem to be using MVars 
for mutual exclusion. 

With the 0.0.3 version of leveldb-haskell, the get and put operations were in 
the IO monad, which made it trivial to write something like this:

withMVar state $ \db - do
  maybeValue - get db rdOpts key
  put db wrOpts key $ maybe init incr maybeValue

Now with the HEAD version, the get and put operations have types:

get :: MonadResource m = DB - ReadOptions - ByteString - m (Maybe 
ByteString)
put :: MonadResource m = DB - WriteOptions - ByteString - ByteString - m ()

I don't think it makes sense in general to lift the withMVar into MonadResource 
and use runResourceT to run its body in IO. This would not satisfy the 
intention behind using ResourceT -- resource allocated inside the withMVar body 
would be deallocated when the withMVar scope is exited, rather than being 
managed by the outermost ResourceT. (Although, in this case we aren't 
allocating any resources, so maybe it's a moot point for my simple example.)

I also don't think it makes sense to use takeMVar and putMVar instead of 
withMVars as this would subvert the exception handling that withMVars provides. 
And my attempts to define a withMVarR (in the ResourceT IO monad) also seem to 
require runResourceT:

withMVarR :: MVar a - (a - ResourceT IO b) - ResourceT IO b
withMVarR m io = do
  -- mask $ \restore - do
a - lift $ takeMVar m
b - {-restore-} (io a) `onExceptionR` (lift $ putMVar m a)
lift $ putMVar m a
return b

onExceptionR :: ResourceT IO a - ResourceT IO b - ResourceT IO a
onExceptionR a b = do
  runResourceT $ transResourceT (\a - transResourceT (onException a) b) a

Maybe I need to create a HasMVar class analogous to HasRef? 
(http://hackage.haskell.org/packages/archive/conduit/0.0.0/doc/html/Control-Monad-Trans-Resource.html#t:HasRef)

I'd appreciate any suggestions on how to make these fit together. 

Warren___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] using ResourceT with MVars

2012-05-02 Thread Michael Snoyman
On Wed, May 2, 2012 at 11:36 AM, Warren Harris warrensomeb...@gmail.com wrote:
 I would like to use LevelDB in my code, and the HEAD version of
 leveldb-haskell now uses runResourceT to manage open db connections and
 iterators. I would also like to run multiple threads, and coordinate them
 for transaction-like behavior, i.e. read and writing data without
 interruption. LevelDB doesn't support transactions itself, so the
 alternative would seem to be using MVars for mutual exclusion.

 With the 0.0.3 version of leveldb-haskell, the get and put operations were
 in the IO monad, which made it trivial to write something like this:

 withMVar state $ \db - do
   maybeValue - get db rdOpts key
   put db wrOpts key $ maybe init incr maybeValue

 Now with the HEAD version, the get and put operations have types:

 get :: MonadResource m = DB - ReadOptions - ByteString - m
 (Maybe ByteString)
 put :: MonadResource m = DB - WriteOptions - ByteString - ByteString -
 m ()

 I don't think it makes sense in general to lift the withMVar into
 MonadResource and use runResourceT to run its body in IO. This would not
 satisfy the intention behind using ResourceT -- resource allocated inside
 the withMVar body would be deallocated when the withMVar scope is exited,
 rather than being managed by the outermost ResourceT. (Although, in this
 case we aren't allocating any resources, so maybe it's a moot point for my
 simple example.)

 I also don't think it makes sense to use takeMVar and putMVar instead of
 withMVars as this would subvert the exception handling that withMVars
 provides. And my attempts to define a withMVarR (in the ResourceT IO monad)
 also seem to require runResourceT:

 withMVarR :: MVar a - (a - ResourceT IO b) - ResourceT IO b
 withMVarR m io = do
   -- mask $ \restore - do
     a - lift $ takeMVar m
     b - {-restore-} (io a) `onExceptionR` (lift $ putMVar m a)
     lift $ putMVar m a
     return b

 onExceptionR :: ResourceT IO a - ResourceT IO b - ResourceT IO a
 onExceptionR a b = do
   runResourceT $ transResourceT (\a - transResourceT (onException a) b) a

 Maybe I need to create a HasMVar class analogous to HasRef?
 (http://hackage.haskell.org/packages/archive/conduit/0.0.0/doc/html/Control-Monad-Trans-Resource.html#t:HasRef)

 I'd appreciate any suggestions on how to make these fit together.

 Warren

 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe


I don't really know the details of LevelDB, but if the question is
how do I run MVar operations in ResourceT, the answer would be
lifted-base[1]. Since ResourceT is an instance of MonadBaseControl,
you can use any of the functions in Control.Concurrent.MVar.Lifted.

Michael

[1] 
http://hackage.haskell.org/packages/archive/lifted-base/0.1.1/doc/html/Control-Concurrent-MVar-Lifted.html

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] using ResourceT with MVars

2012-05-02 Thread Warren Harris

On May 2, 2012, at 2:06 AM, Michael Snoyman wrote:

 
 I don't really know the details of LevelDB, but if the question is
 how do I run MVar operations in ResourceT,

yes

 the answer would be
 lifted-base[1]. Since ResourceT is an instance of MonadBaseControl,
 you can use any of the functions in Control.Concurrent.MVar.Lifted.

Perfect. I didn't know about lifted-base. Many thanks,

Warren

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] heterogeneous environment

2012-05-02 Thread oleg

Ben wrote:

 - use Data.Unique to identify Refs, and use existential quantification
 or Data.Dynamic to create a heterogenous Map from uid to log.  for
 example, to represent a log of compare-and-swaps we might do something
 like

 data Ref a = Ref (IORef a) Unique
 data OpaqueCAS = forall a . 
   OpaqueCAS { casRef :: Ref a, oldVal :: a, newVal :: a }
 type CASLog = Map Unique OpaqueCAS
 logCAS r@(Ref _ uid) o n log = insert uid (OpaqueCAS r o n) log...

 but what if the transaction wants to perform a second CAS on a
 reference we've already CAS'd?  then we should create a combined
 OpaqueCAS record which expects t he first oldVal and swaps in the
 second newVal.  unfortunately the type checker balks at this, as it
 can't prove that the type variable 'a from the first record is the
 same as the 'a in the new record; i suppose there might be some fancy
 type shenanigans which might solve this...

It seems you actually prefer this solution, if it worked. This
solution will entail some run-time check one way or another, because
we `erase' types when we store them in the log and we have to recover
them later.

If the problem is of merging two CASLog entries into one, your code above
already solves it. There are no type shenanigans are necessary. I will make
slight modification though by introducing an extra IORef for
`ephemeral'  communication. Values written to that IORef almost
immediately retrieved. It is not strictly necessary since your Ref
already has one IORef; I assume that it can't be garbled, even for a
brief moment.

The complete code is enclosed at the end of the message.

If one wants to live a bit dangerously but efficiently, one may wish to
create a module of reference cells indexed by unique numbers, like
your Ref. The data constructor Ref is not exported. If the only way to
create Refs is to use the function newRef of the module, and that
function assuredly creates a Ref with a unique label, one is justified
in writing the function

cast :: Ref a - Ref b - Maybe (Ref b)
cast r1@(Ref _ u1) (Ref _ u2) | u1 == u2 - Just (unsafeCoerce r1)
cast _ _ = Nothing

because the same labels correspond to references of the same type.

The _safe_ solution, similar to that in the enclosed code below, was
used in HANSEI, which is the embedded DSL for probabilistic
programming. Here is the relevant code describing first-class memory
(it is OCaml).

(* We often use mutable variables as `communication channel', to appease
   the type-checker. The variable stores the `option' value --
   most of the time, None. One function writes a Some x value,
   and another function almost immediately reads the value -- exactly
   once. The protocol of using such a variable is a sequence of
   one write almost immediately followed by one read.
   We use the following helpers to access our `communication channel'.
*)
let from_option = function Some x - x | None - failwith fromoption;;

let read_answer r = let v = from_option !r in r := None; v (* for safety *)

(* First-class storage: for the implementation of `thread-local' memory *)
module Memory = struct
  type 'a loc = int * 'a option ref 
  type cell   = unit - unit
  module M = Map.Make(struct type t = int let compare x y = x - y end)
  type mem = cell M.t
  let newm = M.empty
  let genid : unit - int = (* generating fresh locations *)
let counter = ref 0 in
fun () - let v = !counter in counter := succ v; v
  let new_loc () = (genid (), ref None)
  let new_cell (_,chan) x = fun () - chan := Some x
  let mref (id,chan) m =
let cell = M.find id m in
cell (); read_answer chan
  let mset ((id,chan) as loc) x m =
M.add id (new_cell loc x) m
end;;


Enclosed Haskell code:

{-# LANGUAGE ExistentialQuantification #-}

module Ref where

import Data.IORef
import Data.Unique
import Data.Map as M

data Ref a = Ref (IORef a) (IORef a) Unique
data OpaqueCAS = 
forall a . OpaqueCAS { casRef :: Ref a, oldVal :: a, newVal :: a }
type CASLog = M.Map Unique OpaqueCAS
logCAS r@(Ref _ _ uid) o n log = M.insert uid (OpaqueCAS r o n) log

-- If one is bothered with undefined below, use Nothing
newRef :: a - IO (Ref a)
newRef x = do
   r1 - newIORef x
   r2 - newIORef undefined -- auxiliary
   u - newUnique
   return (Ref r1 r2 u)

writeOld :: OpaqueCAS - IO ()
writeOld (OpaqueCAS (Ref _ ra _) o n) = writeIORef ra o

readOld :: OpaqueCAS - IO OpaqueCAS
readOld (OpaqueCAS r@(Ref _ ra _) _ n) = do
o - readIORef ra
-- guard against errors and memory leaks
writeIORef ra undefined
return (OpaqueCAS r o n)


writeNew :: OpaqueCAS - IO ()
writeNew (OpaqueCAS (Ref _ ra _) o n) = writeIORef ra n


readNew :: OpaqueCAS - IO OpaqueCAS
readNew (OpaqueCAS r@(Ref _ ra _) o _) = do
n - readIORef ra
-- guard against errors and memory leaks
  

[Haskell-cafe] Arithmetic expressions with GADTs: parsing

2012-05-02 Thread j . romildo
Hello.

In order to learn GADTs, I have written the attached program, which
defines a type for arithmetic expressions using GADTs, a parser for
them, and an evaluation function.

But my parser does not typecheck. ghc-7.4.1 gives me the error message:

Expr.hs:25:28:
Couldn't match expected type `Double' with actual type `Bool'
Expected type: Bool - Expr Double
  Actual type: Bool - Expr Bool
In the first argument of `($)', namely `B'
In the first argument of `(|)', namely `B $ pBool'

Any clues on how to fix that?

Romildo
{-# LANGUAGE GADTs #-}

module Expr where

import Text.Parsec
import Text.Parsec.String
import Control.Applicative (($),($),(*))
import Data.Char

data Op where
  Add :: Op
  Sub :: Op
  Mul :: Op
  Div :: Op

data Expr a where
  N :: Double - Expr Double
  B :: Bool - Expr Bool
  O :: Op - Expr Double - Expr Double - Expr Double
  E :: Expr Double - Expr Double - Expr Bool


pExpr = chainl1 pTerm   (O Add $ pToken + | O Sub $ pToken -)
pTerm = chainl1 pFactor (O Mul $ pToken * | O Div $ pToken /)
pFactor   = N $ pNum | B $ pBool | between (pToken () (pToken )) pExpr
pNum  = read $ pLexeme (many1 (satisfy isDigit))
pBool = (pToken t  return (B True)) | (pToken f  return (B False))

pToken   :: String - Parser String
pToken t  = pLexeme (string t)
pLexeme p = p * many (satisfy isSpace)
  

opf Add = (+)
opf Sub = (-)
opf Mul = (*)
opf Div = (/)

eval :: Expr a - a
eval (N n)  = n
eval (B b)  = b
eval (O op l r) = opf op (eval l) (eval r)
eval (E l r)= eval l == eval r

main = do line - getLine
  case parse pExpr  line of
Left msg - putStrLn (show msg)
Right e - putStrLn (eval e)
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Arithmetic expressions with GADTs: parsing

2012-05-02 Thread Roman Cheplyaka
* j.romi...@gmail.com j.romi...@gmail.com [2012-05-02 08:03:45-0300]
 Hello.
 
 In order to learn GADTs, I have written the attached program, which
 defines a type for arithmetic expressions using GADTs, a parser for
 them, and an evaluation function.
 
 But my parser does not typecheck. ghc-7.4.1 gives me the error message:
 
 Expr.hs:25:28:
 Couldn't match expected type `Double' with actual type `Bool'
 Expected type: Bool - Expr Double
   Actual type: Bool - Expr Bool
 In the first argument of `($)', namely `B'
 In the first argument of `(|)', namely `B $ pBool'
 
 Any clues on how to fix that?

The alternatives given to | must be of the same type. In your case,
one is Expr Double and one is Expr Bool.

Inclusion of pBool in pFactor is probably a mistake — unless you're
going to multiply booleans.

-- 
Roman I. Cheplyaka :: http://ro-che.info/

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Arithmetic expressions with GADTs: parsing

2012-05-02 Thread j . romildo
On Wed, May 02, 2012 at 03:02:46PM +0300, Roman Cheplyaka wrote:
 * j.romi...@gmail.com j.romi...@gmail.com [2012-05-02 08:03:45-0300]
[...]
 The alternatives given to | must be of the same type. In your case,
 one is Expr Double and one is Expr Bool.
 
 Inclusion of pBool in pFactor is probably a mistake — unless you're
 going to multiply booleans.

You are right in the sense that I cannot mix Expr Bool and Expr Double
in a (O op l r) expression. 

But the parser should be able to parse any form of expressions. So I
rewrite my program to take this into account.

The new versions still does not compile:

Expr.hs:27:23:
Couldn't match expected type `Double' with actual type `Bool'
Expected type: ParsecT
 String () Data.Functor.Identity.Identity (Expr Double)
  Actual type: ParsecT
 String () Data.Functor.Identity.Identity (Expr Bool)
In the first argument of `(|)', namely `pBool'
In the second argument of `(|)', namely `pBool | pEqual'

Romildo
{-# LANGUAGE GADTs #-}
{-# LANGUAGE StandaloneDeriving #-}

module Expr where

import Text.Parsec
import Text.Parsec.String
import Control.Applicative (($),($),(*),(*))
import Data.Char

data Op where
  Add :: Op
  Sub :: Op
  Mul :: Op
  Div :: Op
  deriving (Show)

data Expr a where
  N :: Double - Expr Double
  B :: Bool - Expr Bool
  O :: Op - Expr Double - Expr Double - Expr Double
  E :: Expr Double - Expr Double - Expr Bool

deriving instance Show (Expr a)


pExpr = pArit | pBool | pEqual
pArit = chainl1 pTerm (O Add $ pToken + | O Sub $ pToken -)
pTerm = chainl1 pFactor (O Mul $ pToken * | O Div $ pToken /)
pFactor   = N $ pNum | between (pToken () (pToken )) pArit
pNum  = read $ pLexeme (many1 (satisfy isDigit))
pBool = (pToken t  return (B True)) | (pToken f  return (B False))
pEqual= E $ pArit * pToken = * pArit

pToken   :: String - Parser String
pToken t  = pLexeme (string t)
pLexeme p = p * many (satisfy isSpace)
  

opf Add = (+)
opf Sub = (-)
opf Mul = (*)
opf Div = (/)

eval :: Expr a - a
eval (N n)  = n
eval (B b)  = b
eval (O op l r) = opf op (eval l) (eval r)
eval (E l r)= eval l == eval r

-- main = do line - getLine
--   case parse pExpr  line of
-- Left msg - putStrLn (show msg)
-- Right e - putStrLn (eval e)
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] heterogeneous environment

2012-05-02 Thread Heinrich Apfelmus

Ben wrote:

while working on an STM-like library, i ran into the issue of trying
to create a transaction log for reads / writes of heterogeneous
reference types.  i don't have a good answer to this problem.  the
problem is twofold : first, the general heterogeneous collection
problem, and second, connecting a reference to its log.


I've had similar problems while implementing my reactive-banana library. 
The solution is described here


   http://apfelmus.nfshost.com/blog/2011/09/04-vault.html

and also available as a cabal package

   http://hackage.haskell.org/package/vault

Note that the  Vault  data type is probably not quite what you are 
looking for as it represents a whole collection of references. But have 
a look at the type  Data.Vault.Locker  in the vault-0.2 package which I 
have just uploaded to hackage.


Oleg's email describes essentially the same solution.


Best regards,
Heinrich Apfelmus

--
http://apfelmus.nfshost.com


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Arithmetic expressions with GADTs: parsing

2012-05-02 Thread Sean Leather
Hi Romildo,

On Wed, May 2, 2012 at 3:08 PM, j.romildo wrote:

 You are right in the sense that I cannot mix Expr Bool and Expr Double
 in a (O op l r) expression.

 But the parser should be able to parse any form of expressions. So I
 rewrite my program to take this into account.

 The new versions still does not compile:

 Expr.hs:27:23:
 Couldn't match expected type `Double' with actual type `Bool'
 Expected type: ParsecT
 String () Data.Functor.Identity.Identity (Expr Double)
  Actual type: ParsecT
 String () Data.Functor.Identity.Identity (Expr Bool)
In the first argument of `(|)', namely `pBool'
In the second argument of `(|)', namely `pBool | pEqual'


You appear to still be having the same problem. Perhaps this because you
don't quite understand the type error? Let me help you dissect it. Since
this is a type error, I'm not going to assume anything about what should or
should not work. I'll only look at the types.

First, let's comment out the offending line, so that your file type-checks:

Line 27: -- pExpr = pArit | pBool | pEqual

Next, let's look at each of the components relevant to the type error. The
first mentioned is (|). In GHCi, we can find out more information about
that:

*Expr :i (|)
(|) :: ParsecT s u m a - ParsecT s u m a - ParsecT s u m a
  -- Defined in Text.Parsec.Prim
infixr 1 |

From this, we see that the same type parameters to ParsecT are used in the
two argument types as well as the result type. We also see that (|) is a
right-associative infix operator. So, this means the offending line could
be parenthesized as pArit | (pBool | pEqual), which fits the second
part of the type error, pBool | pEqual. Looking at the types of those, we
see:

*Expr :t pBool
pBool :: ParsecT String () Data.Functor.Identity.Identity (Expr Bool)
*Expr :t pEqual
pEqual :: ParsecT String () Data.Functor.Identity.Identity (Expr Double)

As we saw with the type of (|), these two types should be the same (as
in unifiable). However, they are not, because the two type arguments to the
Expr GADT differ: Bool in one case and Double in the other. GHC cannot
match (unify) these types.

Now, to the goal of your project: You say that the parser should be able
to parse any form of expressions, but since you are using a GADT with the
expected expression types in the result index of each constructor, you can
only define parsers that each parse an expression of a single type. That
is, you can have a parser for Expr Bool and a parser for Expr Double, but
these parsers can not be alternatives of another Expr and still have a
valid type. This is, of course, the reason for using the type index as it
is: you don't want Bool where you expect Double and vice versa.

As a general comment, you may want to consider simplifying your goal to
parsing only expressions of type Double. Then, what happens to your Bool
constructors? Well, you could drop them, or you could extend your GADT with
an if constructor that takes a boolean condition with Double alternatives.

Regards,
Sean
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] ANN: HacPhi 2012

2012-05-02 Thread Chris Casinghino
Greetings,

I am very pleased to officially announce Hac Phi 2012, a Haskell
hackathon/get-together to be held August 3-5 at the University of
Pennsylvania in Philadelphia.  The hackathon will officially kick
off at 2:30 Friday afternoon, and go until 5pm on Sunday (with
breaks for sleep, of course).  Last year's Hac Phi was a lot of
fun, drawing more than 30 Haskellers, and many people have
already expressed interest in coming back this year.  Come meet
your Haskelly comrades-in-arms!  I want to stress that everyone
is welcome - you do not have to be a Haskell guru.  Helping hack
on someone else's project could be a great way to increase your
Haskell-fu.

If you plan on coming, please officially register [1].
Registration, travel, lodging and many other details can be found
on the Hac Phi wiki [2].  This year, we are making a public list
of attendees' names and nicks - please let us know if you'd
prefer not to be listed when you register.

We're also looking for a few people interested in giving
short (15-20 min.) talks, probably on Saturday afternoon.
Anything of interest to the Haskell community is fair game - a
project you've been working on, a paper, a quick tutorial.  If
you'd like to give a talk, add it on the wiki [3].

Hac Phi 2012 is supported by contributions from Amgen and Jane
Street.

Hope to see you in Philadelphia!

- The Hac Phi team
Brent Yorgey (byorgey)
Daniel Wagner (dmwit)
Chris Casinghino (ccasin)

[1] http://www.haskell.org/haskellwiki/Hac_%CF%86/Register
[2] http://www.haskell.org/haskellwiki/Hac_%CF%86
[3] http://www.haskell.org/haskellwiki/Hac_%CF%86/Talks

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Learn you

2012-05-02 Thread Brent Yorgey
I am curious how the title was translated.  Of course, the English
title Learn You a Haskell for Great Good uses intentionally
ungrammatical/unidiomatic English for humorous effect.  Is the
Japanese title also ungrammatical/unidiomatic Japanese?  Or do
Japanese speakers not find that humorous?

-Brent

On Wed, May 02, 2012 at 03:59:18PM +0900, Kazu Yamamoto wrote:
 Hello cafe,
 
 Translating Learn You a Haskell for Great Good into Japanese was
 finished and will be published on 22 May. I guess it's worth watching
 its cover page:
 
   
 http://www.amazon.co.jp/%E3%81%99%E3%81%94%E3%81%84Haskell%E3%81%9F%E3%81%AE%E3%81%97%E3%81%8F%E5%AD%A6%E3%81%BC%E3%81%86-Miran-Lipova%C4%8Da/dp/4274068854
 
 There are two translators: Tanaka is the author of peggy and Muranushi is
 the author of Monadius.
 
 Regards,
 
 --Kazu
 
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Learn you

2012-05-02 Thread Colin Adams
I don't find it (the English title) humorous. I just assumed it was written
by a non-native English speaker.

On 2 May 2012 18:18, Brent Yorgey byor...@seas.upenn.edu wrote:

 I am curious how the title was translated.  Of course, the English
 title Learn You a Haskell for Great Good uses intentionally
 ungrammatical/unidiomatic English for humorous effect.  Is the
 Japanese title also ungrammatical/unidiomatic Japanese?  Or do
 Japanese speakers not find that humorous?

 -Brent

 On Wed, May 02, 2012 at 03:59:18PM +0900, Kazu Yamamoto wrote:
  Hello cafe,
 
  Translating Learn You a Haskell for Great Good into Japanese was
  finished and will be published on 22 May. I guess it's worth watching
  its cover page:
 
 
 http://www.amazon.co.jp/%E3%81%99%E3%81%94%E3%81%84Haskell%E3%81%9F%E3%81%AE%E3%81%97%E3%81%8F%E5%AD%A6%E3%81%BC%E3%81%86-Miran-Lipova%C4%8Da/dp/4274068854
 
  There are two translators: Tanaka is the author of peggy and Muranushi
 is
  the author of Monadius.
 
  Regards,
 
  --Kazu
 
  ___
  Haskell-Cafe mailing list
  Haskell-Cafe@haskell.org
  http://www.haskell.org/mailman/listinfo/haskell-cafe

 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Learn you

2012-05-02 Thread Brandon Allbery
On 2 May 2012 18:18, Brent Yorgey byor...@seas.upenn.edu wrote:

 I am curious how the title was translated.  Of course, the English
 title Learn You a Haskell for Great Good uses intentionally
 ungrammatical/unidiomatic English for humorous effect.  Is the


On Wed, May 2, 2012 at 1:25 PM, Colin Adams colinpaulad...@gmail.comwrote:

 I don't find it (the English title) humorous. I just assumed it was
 written by a non-native English speaker.


The English title does require a little context for the humor:  it
leverages a chain of poor-translation memes going back (at least) to
all-your-base.

-- 
brandon s allbery  allber...@gmail.com
wandering unix systems administrator (available) (412) 475-9364 vm/sms
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Learn you

2012-05-02 Thread Wojciech Jedynak
(caveat: I'm not a native speaker of Japanese)

I think the Japanese title is in a similar spirit as the original one.
Breaking it down:

Sugoi Haskell tanoshiku manabou!

sugoi - awesome (rather colloquial)
tanoshiku - while having fun
manabou - let's learn

In formal grammar it should be Sugoi Haskell tanoshiku WO manabou! -
this WO is a particle identifying the object and this omission is
normal in colloquial, spoken Japanese.

How does the Japanese title sound to native speakers? I'm curious myself :)

Wojciech


2012/5/2 Brent Yorgey byor...@seas.upenn.edu:
 I am curious how the title was translated.  Of course, the English
 title Learn You a Haskell for Great Good uses intentionally
 ungrammatical/unidiomatic English for humorous effect.  Is the
 Japanese title also ungrammatical/unidiomatic Japanese?  Or do
 Japanese speakers not find that humorous?

 -Brent

 On Wed, May 02, 2012 at 03:59:18PM +0900, Kazu Yamamoto wrote:
 Hello cafe,

 Translating Learn You a Haskell for Great Good into Japanese was
 finished and will be published on 22 May. I guess it's worth watching
 its cover page:

       
 http://www.amazon.co.jp/%E3%81%99%E3%81%94%E3%81%84Haskell%E3%81%9F%E3%81%AE%E3%81%97%E3%81%8F%E5%AD%A6%E3%81%BC%E3%81%86-Miran-Lipova%C4%8Da/dp/4274068854

 There are two translators: Tanaka is the author of peggy and Muranushi is
 the author of Monadius.

 Regards,

 --Kazu

 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe

 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Learn you

2012-05-02 Thread Bardur Arantsson

On 05/02/2012 07:37 PM, Brandon Allbery wrote:

On 2 May 2012 18:18, Brent Yorgeybyor...@seas.upenn.edu  wrote:


I am curious how the title was translated.  Of course, the English
title Learn You a Haskell for Great Good uses intentionally
ungrammatical/unidiomatic English for humorous effect.  Is the



On Wed, May 2, 2012 at 1:25 PM, Colin Adamscolinpaulad...@gmail.comwrote:


I don't find it (the English title) humorous. I just assumed it was
written by a non-native English speaker.



The English title does require a little context for the humor:  it
leverages a chain of poor-translation memes going back (at least) to
all-your-base.



I always thought it was a nod to

   Borat: Cultural Learnings of America for Make Benefit Glorious 
Nation of Kazakhstan


Regards,


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Learn you

2012-05-02 Thread Felipe Almeida Lessa
On Wed, May 2, 2012 at 2:41 PM, Wojciech Jedynak wjedy...@gmail.com wrote:
 In formal grammar it should be Sugoi Haskell tanoshiku WO manabou! -
 this WO is a particle identifying the object and this omission is
 normal in colloquial, spoken Japanese.

My basic Japanase is very rusty, but shouldn't that be sugoi Haskell
wo tanoshiku manabou?  Not trying to find errors, just trying to
learn something myself =).

Cheers,

-- 
Felipe.

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Learn you

2012-05-02 Thread Brandon Allbery
On Wed, May 2, 2012 at 2:02 PM, Bardur Arantsson s...@scientician.netwrote:

 On 05/02/2012 07:37 PM, Brandon Allbery wrote:

 The English title does require a little context for the humor:  it
 leverages a chain of poor-translation memes going back (at least) to
 all-your-base.

 I always thought it was a nod to

   Borat: Cultural Learnings of America for Make Benefit Glorious Nation of
 Kazakhstan


They're both doing the same thing, AYB came a bit earlier than Borat
though.

-- 
brandon s allbery  allber...@gmail.com
wandering unix systems administrator (available) (412) 475-9364 vm/sms
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Learn you

2012-05-02 Thread Wojciech Jedynak
2012/5/2 Felipe Almeida Lessa felipe.le...@gmail.com:
 On Wed, May 2, 2012 at 2:41 PM, Wojciech Jedynak wjedy...@gmail.com wrote:
 In formal grammar it should be Sugoi Haskell tanoshiku WO manabou! -
 this WO is a particle identifying the object and this omission is
 normal in colloquial, spoken Japanese.

 My basic Japanase is very rusty, but shouldn't that be sugoi Haskell
 wo tanoshiku manabou?  Not trying to find errors, just trying to
 learn something myself =).

You're right, of course :-)

Wojciech

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Threads and hGetLine

2012-05-02 Thread Johannes Waldmann

 There are two threads, one which is waits on input via 
 hGetLine
 and another, which should terminate this thread or close this handle.

like this? The trick is to fork the blocking call (hGetLine)
and wait on an MVar. That way, the kill signal can be handled:

{-# language PatternSignatures #-}

import Control.Concurrent
import Control.Concurrent.MVar
import Control.Exception
import System.IO

main = do
  pid - forkIO $ do
s - wawiter
putStrLn s
  threadDelay $ 5 * 10^6
  killThread pid
  
waiter = do  
  v - newEmptyMVar
  forkIO $ do s - hGetLine stdin ; putMVar v s
  readMVar v `Control.Exception.catch` 
\ (e :: AsyncException ) -  return killed

PS: and I refuse to use the ScopedTypeVariables pragma
since obviously there are no type variables.



___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Edmonton Functional Programming Users Group (EFPUG)

2012-05-02 Thread Kevin Charter
Hi Cafe,

If you live in the Edmonton, Canada area, and you're interested in
functional programming, EFPUG is an informal discussion group you might
find interesting. Most of our talks have been on Haskell topics, but we're
interested in functional languages in general.

Our Google Group is
https://groups.google.com/forum/?fromgroupshl=en#!forum/edmonton-functional-programming-users-group

We meet on the first Tuesday of (almost) each month at the Computing
Science building on the University of Alberta north campus. New
participants, and new ideas for talks, hack nights, or other FP-related
activities, are always welcome.

Cheers,

Kevin
-- 
Kevin Charter
kevin.char...@acm.org
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] OpenGL: No instance for Random GLfloat

2012-05-02 Thread Mark Spezzano
Hi Haskellers,

I'm trying to generate a random vertex in OpenGL as follows.

genPosition :: IO (Vertex3 GLfloat)
genPosition = do x - getStdRandom $ randomR (-1.6,1.6)
   y - getStdRandom $ randomR (-1.0,1.0)
  return (Vertex3 x y (-1))

Unfortunately the compiler complains about me having to implement an instance 
of Random for  GLfloat.

How do I do this (or avoid having to do this)?

Cheers,

Mark


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Haskell source AST zipper with state

2012-05-02 Thread Tony Morris
Is there a library to traverse a source AST keeping state?

-- 
Tony Morris
http://tmorris.net/



___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] heterogeneous environment

2012-05-02 Thread Ben
thanks oleg and heinrich for the solutions; i'll definitely take a look at the 
vault package.  i'll probably end up using unsafeCoerce though, it's too 
tempting (shame on me.)

On May 2, 2012, at 2:33 AM, o...@okmij.org wrote:

 It seems you actually prefer this solution, if it worked. This
 solution will entail some run-time check one way or another, because
 we `erase' types when we store them in the log and we have to recover
 them later.

actually i don't prefer this solution.  i'm interested to hear if there are 
other solutions (or ways to avoid the problem entirely.)  i don't know what to 
search for, something like interpreters with environments with heterogeneous 
types.  i find the circuit-diagram / functional representation the most 
interesting, but it seems unfortunately syntactically impossible.

best, ben
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Haskell source AST zipper with state

2012-05-02 Thread Andrew Seniuk
On Wed, May 2, 2012 at 7:20 PM, Tony Morris tonymor...@gmail.com wrote:
 Is there a library to traverse a source AST keeping state?

Hi Tony, I was able to do this [1] using haskell-src-exts and a state
monad.  AST traversal is possible due to HSE deriving instances for
Data in all its datatype declarations, but the traversals were of a
generic variety, rather than zippers.  I read Scrap Your Zippers [2]
and looked at various other generic zipper libs, but in the end I
managed without zippers.  Note that most zipper libs require instance
declarations for all the syntax datatypes -- Scrap Your Zippers only
requires the Data instances that HSE comes with, not sure why I was
unable to use it, probably just inexperience.

Note that the Annotated version of the HSE parser/AST will probably
not provide enough
 generality for the sorts of attributes you want to store (it's for
source locations, unless something changed in the most recent
release).

Best of luck, and I'll be interested to hear other responses!

-Andrew

[1] http://hackage.haskell.org/freesect (in particular FreeSect*.hs)
[2] https://www.cs.indiana.edu/~adamsmd/papers/scrap_your_zippers/

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] OpenGL: No instance for Random GLfloat

2012-05-02 Thread Patrick Palka
Because GLfloat is simply a newtype wrapper for CFloat, which has a Random
instance, I would do:

{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
deriving instance Random GLFloat

On Wed, May 2, 2012 at 6:29 PM, Mark Spezzano
mark.spezz...@chariot.net.auwrote:

 Hi Haskellers,

 I'm trying to generate a random vertex in OpenGL as follows.

 genPosition :: IO (Vertex3 GLfloat)
 genPosition = do x - getStdRandom $ randomR (-1.6,1.6)
   y - getStdRandom $ randomR (-1.0,1.0)
  return (Vertex3 x y (-1))

 Unfortunately the compiler complains about me having to implement an
 instance of Random for  GLfloat.

 How do I do this (or avoid having to do this)?

 Cheers,

 Mark


 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Haskell Weekly News: Issue 225

2012-05-02 Thread Daniel Santa Cruz
  Welcome to issue 225 of the HWN, an issue covering crowd-sourced bits
  of information about Haskell from around the web. This issue covers the
  week of April 22 to 28, 2012.

Announcements

  Matthias Fischmann made a call for participation to the Hong Kong
  Haskell hackathon, with tentative dates of May 11-13 or 25-27. Follow
  to link for more information.
  [1] http://goo.gl/9sRLF

  HacPhi, the hackathon in Philadelphia, Pennsylvania, USA, will be
  held between August 3-5, 2012.
  [2] http://goo.gl/Rm2qH

Quotes of the Week

   * lambdabot was last seen on #haskell 1 hour, 37 minutes and 46
 seconds ago, saying: IO ()

   * elliott: oh, it's not haskell-cafe? that explains the reasonable
  responses [it = GHC mailing list]

   * Morandat: The astute reader will have noticed that the above
   example clashes with our claim that R is lexically
   scoped. As is often the case, R is lexically scoped
   up to the point it is not.

   * quicksilver: lisp doesn't have equational reasoning so there is
  nothing to lose :)

   * JoeyA: One thing I like about Haskell versus C++ is that abusing
language features tends to give more satisfying results.
 monochrom: that seems to be a criterion for drugs rather than
languages :)

Top Reddit Stories

   * Darcs 2.8: faster, better annotate; patch stash (obliterate -O);
revert hunk split; and more!
 Domain: wiki.darcs.net, Score: 63, Comments: 21
 On Reddit: [3] http://goo.gl/4tj4i
 Original: [4] http://goo.gl/R7TpP

   * The Haskell / Snap ecosystem is as productive (or more) than Ruby/Rails.
 Domain: blog.dbpatterson.com, Score: 63, Comments: 46
 On Reddit: [5] http://goo.gl/cP3NC
 Original: [6] http://goo.gl/23alh

   * Cabal is now hosted on GitHub
 Domain: github.com, Score: 44, Comments: 20
 On Reddit: [7] http://goo.gl/yBqCC
 Original: [8] http://goo.gl/0ze9y

   * Eight Haskell Google Summer of Code projects accepted
 Domain: google-melange.com, Score: 40, Comments: 25
 On Reddit: [9] http://goo.gl/c2KXg
 Original: [10] http://goo.gl/vu681

   * “Live” code update for Haskell
 Domain: self.haskell, Score: 31, Comments: 17
 On Reddit: [11] http://goo.gl/ZZDb6
 Original: [12] http://goo.gl/ZZDb6

   * Functional Programming in C++
 Domain: altdevblogaday.com, Score: 30, Comments: 12
 On Reddit: [13] http://goo.gl/pFuHk
 Original: [14] http://goo.gl/aG6iP

   * Why do we not define IO as a Free monad?
 Domain: self.haskell, Score: 28, Comments: 47
 On Reddit: [15] http://goo.gl/jiSdb
 Original: [16] http://goo.gl/jiSdb

   * Elm: Source code and Compiler/Server now available. Write FRP
code for the web!
 Domain: self.haskell, Score: 27, Comments: 11
 On Reddit: [17] http://goo.gl/9hE6X
 Original: [18] http://goo.gl/9hE6X

   * An experiment with Bayesian Networks in Haskell
 Domain: alpheccar.org, Score: 27, Comments:
 On Reddit: [19] http://goo.gl/21VDw
 Original: [20] http://goo.gl/2piKL

   * More Client Side Yesod: todo sample
 Domain: yesodweb.com, Score: 25, Comments: 10
 On Reddit: [21] http://goo.gl/LGO75
 Original: [22] http://goo.gl/QGsrZ

   * C Style Haskell
 Domain: kormacode.blogspot.com, Score: 24, Comments: 21
 On Reddit: [23] http://goo.gl/VsShj
 Original: [24] http://goo.gl/o75jn


Top StackOverflow Questions

   * Avoiding IORefs in pure code
 votes: 19, answers: 1
 Read on SO: [25] http://goo.gl/327fO

   * How can I get JHC to cooperate with the android ndk?
 votes: 11, answers: 1
 Read on SO: [26] http://goo.gl/oGMQ9

   * Is there a name for this function or pattern?
 votes: 11, answers: 2
 Read on SO: [27] http://goo.gl/HJixe

   * Haskell rank two polymorphism compile error
 votes: 11, answers: 2
 Read on SO: [28] http://goo.gl/hYdRX

   * Python faster than compiled Haskell?
 votes: 11, answers: 5
 Read on SO: [29] http://goo.gl/sUXMa

   * How does one release a *nix project?
 votes: 10, answers: 2
 Read on SO: [30] http://goo.gl/JTgCz

   * Optimizing partial computation in Haskell
 votes: 8, answers: 1
 Read on SO: [31] http://goo.gl/Dncn7

   * Proper way to treat global flags in Haskell
 votes: 8, answers: 2
 Read on SO: [32] http://goo.gl/di2Ld

   * Generating code for another language in Haskell
 votes: 7, answers: 1
 Read on SO: [33] http://goo.gl/OlRCI

   * Why does haskell enumerator based IO call sigprocmask so often?
 votes: 7, answers: 4
 Read on SO: [34] http://goo.gl/kfTSy

   * confused about function as instance of Functor in haskell
 votes: 7, answers: 5
 Read on SO: [35] http://goo.gl/aX9JA

Until next time,
Daniel Santa Cruz

References

   1. http://permalink.gmane.org/gmane.comp.lang.haskell.cafe/98038
   2. http://www.haskell.org/haskellwiki/Hac_%CF%86
   3. http://wiki.darcs.net/Releases/2.8
 

Re: [Haskell-cafe] OpenGL: No instance for Random GLfloat

2012-05-02 Thread Mark Spezzano
Hi,

I tried this but now I get another error:

The data constructors of `GLfloat' are not all in scope
  so you cannot derive an instance for it
In the stand-alone deriving instance for `Random GLfloat'

Mark

On 03/05/2012, at 10:39 AM, Patrick Palka wrote:

 Because GLfloat is simply a newtype wrapper for CFloat, which has a Random 
 instance, I would do:
 
 {-# LANGUAGE StandaloneDeriving #-}
 {-# LANGUAGE GeneralizedNewtypeDeriving #-}
 deriving instance Random GLFloat
 
 On Wed, May 2, 2012 at 6:29 PM, Mark Spezzano mark.spezz...@chariot.net.au 
 wrote:
 Hi Haskellers,
 
 I'm trying to generate a random vertex in OpenGL as follows.
 
 genPosition :: IO (Vertex3 GLfloat)
 genPosition = do x - getStdRandom $ randomR (-1.6,1.6)
   y - getStdRandom $ randomR (-1.0,1.0)
  return (Vertex3 x y (-1))
 
 Unfortunately the compiler complains about me having to implement an instance 
 of Random for  GLfloat.
 
 How do I do this (or avoid having to do this)?
 
 Cheers,
 
 Mark
 
 
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe
 
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Learn you

2012-05-02 Thread Richard O'Keefe

On 3/05/2012, at 5:18 AM, Brent Yorgey wrote:

 I am curious how the title was translated.  Of course, the English
 title Learn You a Haskell for Great Good uses intentionally
 ungrammatical/unidiomatic English for humorous effect.  Is the
 Japanese title also ungrammatical/unidiomatic Japanese?  Or do
 Japanese speakers not find that humorous?

This native speaker of English doesn't find the effect
of the English title funny, despite finding practically
everything in the world, up to and including a bout of
kidney stones, funny.  Humour styles really don't travel
all that well.  The Little Lisper (and the other books
like The Little Schemer and The Seasoned Schemer) are
presumably meant to be funny, but to me come across as
offensively patronising (you are such a drooling idiot
that if we didn't have this heavy laugh track you'd go
to sleep or something).  Such a pity, because they are
such great books if you can refrain from throwing them
out the window every few minutes.

Now if the Japanese title were *perfect* Japanese,
that *would* be funny, because it would be a case
of a good translation being a bad translation.

I did say that humour doesn't travel well...


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe