Re: [Haskell-cafe] Using a monad to decompose a function into functions

2009-03-13 Thread minh thu
2009/3/13 Marcin Kosiba marcin.kos...@gmail.com:
 On Thursday 12 March 2009, you wrote:
 2009/3/12 Marcin Kosiba marcin.kos...@gmail.com:
  Hi,
         I'm doing a bit of research into mobility models and I'm currently
  exploring implementation language choices for the simulator
  (*snip*)
  The simulation algorithm requires expressing
  the node's mobility so that it is stateless. The mobility model
  algorithm's type should be something like:
  mobility_model :: WorldState - NodeState - OtherInput - (Action,
  NodeState)
 
  where Action can alter WorldState and the second NodeState is an altered
  input NodeState. I perform a form of speculative execution on
  mobility_model so sometimes I need to backtrack to a previous world and
  node state. This is all fairly simple stuff, and was just an
  introduction. What I do now is store an enum in NodeState and implement
  mobility_model as one big case statement. Yes, this is very imperative of
  me, I know. What I'd like to do is to express mobility_model, so that the
  code would look like:
 
  mobility_model world node input = do
     do_calculus
     emit_action
     if something
       then emit_action
       else emit_action
     do_calculus
     emit_action
     mobility_model world node input

 Hi,

 It seems you can use
 http://hackage.haskell.org/packages/archive/mtl/latest/doc/html/Control-Mon
ad-State-Lazy.html Just have a look at the exemple :

  tick :: State Int Int
  tick = do n - get
            put (n+1)
            return n

 your code would become something like
 mobility_model :: OtherInput - State (WorldState,NodeState) ()
 mobility_model input = do
   world - gets fst
   node - gets snd
   
   let (world',node') = ...
   put (world',node')

 ok, that solves part of the problem. what this doesn't solve is that somewhere
 between these lines (which corespond to emit_action in my example)
   let (world',node') = ...
   put (world',node')
 I need to return a value and an Action and NodeState to the simulation
 algorithm. and then, after the simulation algorithm calculates a new
 WorldState it will want the mobility_model to where it left off, but with a
 new WorldState.

 I hope I'm clear about what I wish to achieve: each emit_action should return
 a value (Action, NodeState) and maybe a function mobility_model_cont which I
 then could call with the new WorldState to continue from where emit_action
 returned.

I'm not entirely sure ... but I think it doesn't matter that much :)
Here is why.

This was just an exemple :
 mobility_model :: OtherInput - State (WorldState,NodeState) ()

You could also have
 mobility_model :: OtherInput - NodeState - State WorldState
(NodeState,Action)
or whatever.

In fact, the State monad makes it easy to thread (in this context, it
means 'pass around') an argument to many functions, providing a nice
syntax reminiscent of imperative language. But it lets you completely
free of what is passed around. It depends on what you want to be
explicitely passed by argument, and what you want to pass in the state
of the monad (that is, what you want to appear, inside the monad only,
as some global variable).

So in your code, if you often need to pass a WorldState to a function
which should return a modified WorldState, it makes sense to put
WorldState inside the state monad. But, maybe, if there is just a few
functions which act on NodeState, it has not to be part of the state
carried by the state monad.

I'm not entirely sure of what is a problem to you : is it the use of
the State monad, or something else ?
If it can help you to formulate your question you can post some code
(or past it to http://hpaste.org/)...

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


Re: [Haskell-cafe] How to compare PortNumbers or Bug in Network.Socket?

2009-03-13 Thread Bryan O'Sullivan
On Thu, Mar 12, 2009 at 8:45 PM, Antoine Latter aslat...@gmail.com wrote:

 So the Ord instance is wrong for the PortNumber type?  Well, maybe not
 wrong.


It's out and out wrong. You get different results on machines of different
endianness. Now, this begs the question of why not just simply use an
unwrapped Word16 instead :-)
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Dynamically typing TH.Exp at runtime

2009-03-13 Thread Martin Hofmann
Sorry, maybe it I didn't made it clear enough.

 Perhaps I'm misunderstanding something, but since one can infer types
 in GHCI, that implies one can infer types in the GHC API; since Hint
 wraps the GHC API, that implies one can infer types in Hint, doesn't
 it? And indeed, there are functions to infer the type of a String;
 iirc I've even used them myself in mueval.
 
That's true, inferring the type of a string is not the problem. However,
I am not only interested in the top-level type, but also in the type of
any arbitrary subexpression. Consider for example following recursive
definition:

foo [] = []
foo (x:xs) = (:)(x+1)(foo xs)

Typing only the first rule one would says its type is '[a] - [a]'.
However, the second rule specialises the type to 'Num a = [a] - [a]'.
So, if I am interested in the type of the 'x' in the pattern of the
second rule, I need to be aware of its binding on the right-hand side.
Consequently the type of 'x' is 'Num a'.

AFAIK, I need Hendley-Milner type inference for that (please correct me
if I am wrong) and I was wondering if I really need to implement it by
myself, when it is already somewhere inside GHC.

Thanks,

Martin

   

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


Re: [Haskell-cafe] Re: Sugestion for a Haskell mascot

2009-03-13 Thread Wolfgang Jeltsch
Am Donnerstag, 12. März 2009 22:00 schrieb Martijn van Steenbergen:
 Deniz Dogan wrote:
  Then of course,
  there's the downside that there's no connection to the language itself
  in any way.

 I usually go for names that don't have to do anything with the
 application itself: GroteTrap (translates to GreatBustard), Yogurt,
 Custard... saves me from having to think of appropriate names. :-P 

This is basically how I chose the name “Grapefruit” for “my” FRP library. 
Okay, it refers to Fruit (a FRP GUI library) but the only further meaning 
of “Grapefruit” is that I find Grapefruits to be tasty. :-)  Often people 
choose meaningful names and convert them to acronyms, noone can pronounce.

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


Re: [Haskell-cafe] Combining haddock documentation from multiple packages

2009-03-13 Thread Martijn van Steenbergen

Hi Heikki,

Heikki Aitakangas wrote:

Is it possible to generate a unified documentation tree similar to
http://www.haskell.org/ghc/docs/latest/html/libraries/index.html from
packages installed via cabal from hackage? And if so, how does one go
about doing it?


This question was asked recently. See:

http://thread.gmane.org/gmane.comp.lang.haskell.cafe/53531

Martijn.

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


Re: [Haskell-cafe] Natural Numbers: Best implementation?

2009-03-13 Thread Sebastian Fischer

Hi Mark,

On Mar 13, 2009, at 3:54 AM, Mark Spezzano wrote:

I was wondering what the best way to implement Natural number would  
be. Is there a package which already does this?


there are two packages on Hackage that implement natural numbers using  
algebraic datatypes: 'numbers' has a module Data.Number.Natural that  
implements them in unary notation (zero and successor), 'nat' has  
Data.Number.Nat that uses a binary encoding.


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


Re: [Haskell-cafe] Re: Against cuteness

2009-03-13 Thread Wolfgang Jeltsch
Am Freitag, 13. März 2009 04:29 schrieb Benjamin L.Russell:
 Consider the following logo:

 Silver red monad.png
 http://commons.wikimedia.org/wiki/File:Silver_red_monad.png

Can’t we choose something which is not connected to certain worldviews?

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


Re: [Haskell-cafe] State monad is missing Applicative instance

2009-03-13 Thread Wolfgang Jeltsch
Am Freitag, 13. März 2009 05:09 schrieb Denis Bueno:
 This works because every monad induces an Applicative instance in a
 way I've ingested just enough wine to forget. =]

pure = return

(*) = ap

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


Re: [Haskell-cafe] Natural Numbers: Best implementation?

2009-03-13 Thread Roman Cheplyaka
* Alexander Dunlap alexander.dun...@gmail.com [2009-03-12 20:01:57-0700]
 Also, a lot of functions just take
 Integers so it would be more of a pain to use.

AFAIK there are very few fuctions that take Integers. Many functions
take instances of Integral, but it's not a problem to make your own type
such an instance.

-- 
Roman I. Cheplyaka :: http://ro-che.info/
Don't let school get in the way of your education. - Mark Twain
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Natural Numbers: Best implementation?

2009-03-13 Thread Wolfgang Jeltsch
Am Freitag, 13. März 2009 04:01 schrieb Alexander Dunlap:
  2.  Use the type
 
  data Natural = Zero | Succ !Natural

 […]

 In terms of speed, I think that [3] would be reasonably fast (unless
 you do a ton of subtraction with bounds-checking) and [2] would
 probably be quite slow, because you don't get the speed-boost from
 doing computations right on the processor.

Not only that but also because operations like addition now take at least 
linear time.

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


Re: [Haskell-cafe] Natural Numbers: Best implementation?

2009-03-13 Thread Wolfgang Jeltsch
Am Freitag, 13. März 2009 04:53 schrieb Brandon S. Allbery KF8NH:
 On 2009 Mar 12, at 22:54, Mark Spezzano wrote:
  I was wondering what the best way to implement Natural number would
  be. Is there a package which already does this?

 type-level on Hackage.

I think, the original poster wanted value-level naturals, not type-level 
naturals.

  2.  Use the type
  data Natural = Zero | Succ !Natural

 One of the reasons people use type-level naturals is to get laziness;
 you've made this strict.  Is there a reason?

Do you really mean type-level naturals? The following is a definition of 
value-level naturals:

data Natural = Zero | Succ Natural

Type-level naturals would be defined like this:

data Zero

data Succ nat

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


Re: [Haskell-cafe] Using a monad to decompose a function into functions

2009-03-13 Thread Marcin Kosiba
On Friday 13 March 2009, you wrote:
 2009/3/13 Marcin Kosiba marcin.kos...@gmail.com:
  On Thursday 12 March 2009, you wrote:
  2009/3/12 Marcin Kosiba marcin.kos...@gmail.com:
   Hi,
          I'm doing a bit of research into mobility models and I'm
   currently exploring implementation language choices for the simulator
   (*snip*)
   The simulation algorithm requires expressing
   the node's mobility so that it is stateless. The mobility model
   algorithm's type should be something like:
   mobility_model :: WorldState - NodeState - OtherInput - (Action,
   NodeState)
  
   where Action can alter WorldState and the second NodeState is an
   altered input NodeState. I perform a form of speculative execution on
   mobility_model so sometimes I need to backtrack to a previous world
   and node state. This is all fairly simple stuff, and was just an
   introduction. What I do now is store an enum in NodeState and
   implement mobility_model as one big case statement. Yes, this is very
   imperative of me, I know. What I'd like to do is to express
   mobility_model, so that the code would look like:
  
   mobility_model world node input = do
      do_calculus
      emit_action
      if something
        then emit_action
        else emit_action
      do_calculus
      emit_action
      mobility_model world node input
 
  Hi,
 
  It seems you can use
  http://hackage.haskell.org/packages/archive/mtl/latest/doc/html/Control-
 Mon ad-State-Lazy.html Just have a look at the exemple :
 
   tick :: State Int Int
   tick = do n - get
             put (n+1)
             return n
 
  your code would become something like
  mobility_model :: OtherInput - State (WorldState,NodeState) ()
  mobility_model input = do
    world - gets fst
    node - gets snd
    
    let (world',node') = ...
    put (world',node')
 
  ok, that solves part of the problem. what this doesn't solve is that
  somewhere between these lines (which corespond to emit_action in my
  example)
 
    let (world',node') = ...
    put (world',node')
 
  I need to return a value and an Action and NodeState to the simulation
  algorithm. and then, after the simulation algorithm calculates a new
  WorldState it will want the mobility_model to where it left off, but with
  a new WorldState.
 
  I hope I'm clear about what I wish to achieve: each emit_action should
  return a value (Action, NodeState) and maybe a function
  mobility_model_cont which I then could call with the new WorldState to
  continue from where emit_action returned.

 I'm not entirely sure ... but I think it doesn't matter that much :)
 Here is why.

 This was just an exemple :
  mobility_model :: OtherInput - State (WorldState,NodeState) ()

 You could also have
  mobility_model :: OtherInput - NodeState - State WorldState
 (NodeState,Action)
 or whatever.

 In fact, the State monad makes it easy to thread (in this context, it
 means 'pass around') an argument to many functions, providing a nice
 syntax reminiscent of imperative language. But it lets you completely
 free of what is passed around. It depends on what you want to be
 explicitely passed by argument, and what you want to pass in the state
 of the monad (that is, what you want to appear, inside the monad only,
 as some global variable).

 So in your code, if you often need to pass a WorldState to a function
 which should return a modified WorldState, it makes sense to put
 WorldState inside the state monad. But, maybe, if there is just a few
 functions which act on NodeState, it has not to be part of the state
 carried by the state monad.

 I'm not entirely sure of what is a problem to you : is it the use of
 the State monad, or something else ?
 If it can help you to formulate your question you can post some code
 (or past it to http://hpaste.org/)...

Threading the state is not the problem. Maybe this will help:
what I have now:

fsm world state = case state of
  first -
do_stuff_one
(move_up, succ state)
  second -
do_stuff_two
(move_left, succ state)
 third -
 do_stuff_three
 (move_right, first)

what I'd want to have is to say:
fsm world state = do
  do_stuff_one
  yield move_up
  do_stuff_two
  yield move_left
  do_stuff_three
  yield move_right
  fsm world state

and have it translated to:

fsm world state = 
  do_stuff_one
  (move_up, \world' state' -
do_stuff_two
  (move_left, \world'' state'' -
 do_stuff_three
   (move_right, fsm world'' state'')

Thanks!
Marcin Kosiba


signature.asc
Description: This is a digitally signed message part.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Natural Numbers: Best implementation?

2009-03-13 Thread Wolfgang Jeltsch
Am Freitag, 13. März 2009 09:21 schrieb Roman Cheplyaka:
 * Alexander Dunlap alexander.dun...@gmail.com [2009-03-12 20:01:57-0700]

  Also, a lot of functions just take
  Integers so it would be more of a pain to use.

 AFAIK there are very few fuctions that take Integers. Many functions
 take instances of Integral, but it's not a problem to make your own type
 such an instance.

I’d say that it is a problem. Class instances should satisfy certain laws. 
(Although these laws are often not stated explicitely, they are assumed to 
hold by users of the class and they should hold to make the instance 
sensible.) In the case of Num, I would expect num + negate num to equal num. 
This wouldn’t hold for a Natural instance of Num.

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


Re: [Haskell-cafe] Using a monad to decompose a function into functions

2009-03-13 Thread minh thu
2009/3/13 Marcin Kosiba marcin.kos...@gmail.com:
 On Friday 13 March 2009, you wrote:
 2009/3/13 Marcin Kosiba marcin.kos...@gmail.com:
  On Thursday 12 March 2009, you wrote:
  2009/3/12 Marcin Kosiba marcin.kos...@gmail.com:
   Hi,
  I'm doing a bit of research into mobility models and I'm
   currently exploring implementation language choices for the simulator
   (*snip*)
   The simulation algorithm requires expressing
   the node's mobility so that it is stateless. The mobility model
   algorithm's type should be something like:
   mobility_model :: WorldState - NodeState - OtherInput - (Action,
   NodeState)
  
   where Action can alter WorldState and the second NodeState is an
   altered input NodeState. I perform a form of speculative execution on
   mobility_model so sometimes I need to backtrack to a previous world
   and node state. This is all fairly simple stuff, and was just an
   introduction. What I do now is store an enum in NodeState and
   implement mobility_model as one big case statement. Yes, this is very
   imperative of me, I know. What I'd like to do is to express
   mobility_model, so that the code would look like:
  
   mobility_model world node input = do
  do_calculus
  emit_action
  if something
then emit_action
else emit_action
  do_calculus
  emit_action
  mobility_model world node input
 
  Hi,
 
  It seems you can use
  http://hackage.haskell.org/packages/archive/mtl/latest/doc/html/Control-
 Mon ad-State-Lazy.html Just have a look at the exemple :
 
   tick :: State Int Int
   tick = do n - get
 put (n+1)
 return n
 
  your code would become something like
  mobility_model :: OtherInput - State (WorldState,NodeState) ()
  mobility_model input = do
world - gets fst
node - gets snd

let (world',node') = ...
put (world',node')
 
  ok, that solves part of the problem. what this doesn't solve is that
  somewhere between these lines (which corespond to emit_action in my
  example)
 
let (world',node') = ...
put (world',node')
 
  I need to return a value and an Action and NodeState to the simulation
  algorithm. and then, after the simulation algorithm calculates a new
  WorldState it will want the mobility_model to where it left off, but with
  a new WorldState.
 
  I hope I'm clear about what I wish to achieve: each emit_action should
  return a value (Action, NodeState) and maybe a function
  mobility_model_cont which I then could call with the new WorldState to
  continue from where emit_action returned.

 I'm not entirely sure ... but I think it doesn't matter that much :)
 Here is why.

 This was just an exemple :
  mobility_model :: OtherInput - State (WorldState,NodeState) ()

 You could also have
  mobility_model :: OtherInput - NodeState - State WorldState
 (NodeState,Action)
 or whatever.

 In fact, the State monad makes it easy to thread (in this context, it
 means 'pass around') an argument to many functions, providing a nice
 syntax reminiscent of imperative language. But it lets you completely
 free of what is passed around. It depends on what you want to be
 explicitely passed by argument, and what you want to pass in the state
 of the monad (that is, what you want to appear, inside the monad only,
 as some global variable).

 So in your code, if you often need to pass a WorldState to a function
 which should return a modified WorldState, it makes sense to put
 WorldState inside the state monad. But, maybe, if there is just a few
 functions which act on NodeState, it has not to be part of the state
 carried by the state monad.

 I'm not entirely sure of what is a problem to you : is it the use of
 the State monad, or something else ?
 If it can help you to formulate your question you can post some code
 (or past it to http://hpaste.org/)...

 Threading the state is not the problem. Maybe this will help:
 what I have now:

 fsm world state = case state of
  first -
do_stuff_one
(move_up, succ state)
  second -
do_stuff_two
(move_left, succ state)
  third -
 do_stuff_three
 (move_right, first)

 what I'd want to have is to say:
 fsm world state = do
  do_stuff_one
  yield move_up
  do_stuff_two
  yield move_left
  do_stuff_three
  yield move_right
  fsm world state

 and have it translated to:

 fsm world state =
  do_stuff_one
  (move_up, \world' state' -
do_stuff_two
  (move_left, \world'' state'' -
 do_stuff_three
   (move_right, fsm world'' state'')


Sorry, I never used continuations or coroutines in Haskell.
But, if your goal is to be less imperative, I'm not sure using
'yield' is what you want. If what you do is well expressed by
a fsm, maybe you should stick to it.

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


Re: [Haskell-cafe] Does anybody dislike implicit params as much as I do?

2009-03-13 Thread Jules Bean

Thomas Hartman wrote:

http://blog.patch-tag.com/2009/03/09/implicitparams-are-evil-thoughts-on-adapting-gitit/

I understand there are arguments for using IPs, but after this
experience, the ImplicitParams extension is a code smell for me.


It's not just you. Implicit parameters are a scourge on the language.

I think there are also some subtle annoyances with how they make 
apparently 'safe' program rearrangements unsafe, by pushing around let 
?foo = bar in ... bindings.


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


[Haskell-cafe] Re: Typing Dynamic Typing [Was: Dynamically typing TH.Exp at runtime]

2009-03-13 Thread Martin Hofmann
Thanks a lot for the detailed answer. I must admit, I haven't understood
it completely yet, so  please excuse for probably naive questions.

As far as I see from the language defined in Incope.hs, there is only
support for the defined primitive functions (add, mult, if_, etc.).
Using additional functions, I would need to extend it, right? Also
considering Haskell as underlying language using TH as AST is not
possible, because it is polymorphic?

Thanks,

Martin

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


Fwd: [Haskell-cafe] DSLs with {in,}equalities

2009-03-13 Thread Alberto G. Corona
-- Forwarded message --
From: Alberto G. Corona agocor...@gmail.com
Date: 2009/3/13
Subject: Re: [Haskell-cafe] DSLs with {in,}equalities
To: Adam Vogt vogt.a...@gmail.com


You need an expression evaluator:

with
(+) (Const a) (Const b)= Const (a+b)
(*) (Const a) (Const b)= Const (a*b)

eval :: Exp - Integer

eval (Const i)= i
eval ( Plus e1 e2)= eval e1 + eval e2 ..
eval( Mul 

and

instance Ord Expr where
 () expr1 expr2 = eval expr1  eval expr2


by the way:

simplify expr= Const (eval expr)



..

2009/3/13 Alberto G. Corona agocor...@gmail.com

 Sorry(Const a)  (Const b) = a  b

 also

 (*) (Const a) (Const b)= Const (a*b)


 2009/3/13 Alberto G. Corona agocor...@gmail.com

 () :: (Ord a) = a - a - Bool

 what´s the problem?

 make your Expr an instance of Ord.

 By the way

  instance Num Expr where
  fromInterger = Const
  (+) = Plus
  (*) = Times

 does not work. you have not defined (+) and (*) for Const Integer.

 (+) (Const a) (Const b)= Const (a+b)

 With this you have an evaluator.

 In the same way:

 (Const a)  (Const b) = Const (a  b)




 2009/3/12 Adam Vogt vogt.a...@gmail.com

 This seems to be in ghc for those reasons:
 http://www.haskell.org/haskellwiki/Quasiquotation

 * On Monday, March 02 2009, Andrew Hunter wrote:

 Several times now I've had to define an EDSL for working with
 (vaguely) numeric expressions.  For stuff like 2*X+Y, this is easy,
 looking pretty much like:
 
  data Expr = Const Integer | Plus Expr Expr | Times Expr Expr
 
  instance Num Expr where
  fromInterger = Const
  (+) = Plus
  (*) = Times
 
 c.  This lets me get a perfectly nice AST, which is what I want.
 When I want to be able to express and work with inequalities and
 equalities, this breaks.  Suppose I want to write 2*X + Y  3.  I
 either have to:
 
 a) Hide Prelude.() and define a simple  that builds the AST term I
 want.
 b) Come up with a new symbol for it that doesn't look totally awful.
 
 Neither of these work decently well.  Hiding Eq and Ord operators,
 which is what I effectively have to do for a), is pretty much a
 nonstarter--we'll have to use them too much for that to be practical.
 
 On the other hand, b) works...but is about as ugly as it gets.  We
 have lots and lots of symbols that are already taken for important
 purposes that are syntactically near ,=,==, and the like:  and
  and = for monads,  for arrows, etc.  There...are not good
 choices that I know of for the symbols that don't defeat the purpose
 of making a nice clean EDSL for expressions; I might as well use 3*X +
 Y `lessthan` 3, which is just not cool.
 
 Does anyone know of a good solution, here?  Are there good
 substitutions for all the six operators that are important
 (,,=,=,==,/=), that are close enough to be pretty-looking but not
 used for other important modules?
 
 Better yet, though a little harder, is there a nice type trick I'm not
 thinking of?  This works for Num methods but not for Ord methods
 because:
 
 (+) :: (Num a) = a - a - a
 () :: (Ord a) = a - a - Bool
 
 i.e. the return type of comparisons is totally fixed.  I don't suppose
 there's a good way to...well, I don't know what the *right* answer is,
 but maybe define a new typeclass with a more flexible type for  that
 lets both standard types return Bool and my expressions return Expr?
 Any good solution would be appreciated.
 
 Thanks,
 AHH
 ___
 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


[Haskell-cafe] Re: Against cuteness

2009-03-13 Thread Achim Schneider
Benjamin L.Russell dekudekup...@yahoo.com wrote:

 balance

Stop right there. Any further word about what the Taiji means would
only make you look even more clueless. Take a scale if you want a
symbol for balance[1].

OTOH, laziness(yin) and strictness(yang) make a far better pair of
unified opposites than the schemeish eval and apply (which's outer
essences are both yang, changing to yin only by means of what they
execute[2]).

Still, you wouldn't represent the Maybe monad with =, now would you?
Instantiating a symbol for a general principle to whatever you like
constitutes pocketing.


Anyway, I think it's too late for logo submissions. Personally, I just
love the lambda-bind, it's truly haskellish, sleek, appropriately
cryptic and lends itself well to ascii-art.


What about a chicken holding a curry dispenser? In any case, I don't
think a sloth is a bad choice as a mascot: It's most likely the most
efficient animal on earth, and seeing it, you're bound to be mystified
how it manages to get anything done.



Water overcomes stone:
Shapeless, it requires no opening:
The benefit of taking no action.

Yet benefit without action,
And experience without abstraction,
Are practiced by very few.



[1] Or the vector equilibrium (note the word libra in there):
http://www.angelfire.com/mt/marksomers/91.html
It's also the reason why cutting a pizza into anything else but six
pieces is an abomination to geometry.[2]

[2] While I'm at it: The tips of the pinky, index finger, and thumb
form a tetrahedron together with the center of mass in your palm while
holding such a piece. What do you make of that?

[3] And are therefore better explained in terms of hodge and podge

-- 
(c) this sig last receiving data processing entity. Inspect headers
for copyright history. All rights reserved. Copying, hiring, renting,
performance and/or quoting of this signature prohibited.


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


Re: [Haskell-cafe] DSLs with {in,}equalities

2009-03-13 Thread Alberto G. Corona
even at the level of expressions you can be sure that inequalities hold. So
you can create an instance of Ord. for example:
(Sum x z)   y | x== y  z0 = True
  | 

here x and y can be expressions and == can have its own rules

with this you can compute symbolically, because you don´t need to reduce the
expression to a numerical value. It´s a matter of finding rules.

2009/3/13 Alberto G. Corona agocor...@gmail.com

 () :: (Ord a) = a - a - Bool

 what´s the problem?

 make your Expr an instance of Ord.

 By the way

  instance Num Expr where
  fromInterger = Const
  (+) = Plus
  (*) = Times

 does not work. you have not defined (+) and (*) for Const Integer.

 (+) (Const a) (Const b)= Const (a+b)

 With this you have an evaluator.

 In the same way:

 (Const a)  (Const b) = Const (a  b)




 2009/3/12 Adam Vogt vogt.a...@gmail.com

 This seems to be in ghc for those reasons:
 http://www.haskell.org/haskellwiki/Quasiquotation

 * On Monday, March 02 2009, Andrew Hunter wrote:

 Several times now I've had to define an EDSL for working with
 (vaguely) numeric expressions.  For stuff like 2*X+Y, this is easy,
 looking pretty much like:
 
  data Expr = Const Integer | Plus Expr Expr | Times Expr Expr
 
  instance Num Expr where
  fromInterger = Const
  (+) = Plus
  (*) = Times
 
 c.  This lets me get a perfectly nice AST, which is what I want.
 When I want to be able to express and work with inequalities and
 equalities, this breaks.  Suppose I want to write 2*X + Y  3.  I
 either have to:
 
 a) Hide Prelude.() and define a simple  that builds the AST term I
 want.
 b) Come up with a new symbol for it that doesn't look totally awful.
 
 Neither of these work decently well.  Hiding Eq and Ord operators,
 which is what I effectively have to do for a), is pretty much a
 nonstarter--we'll have to use them too much for that to be practical.
 
 On the other hand, b) works...but is about as ugly as it gets.  We
 have lots and lots of symbols that are already taken for important
 purposes that are syntactically near ,=,==, and the like:  and
  and = for monads,  for arrows, etc.  There...are not good
 choices that I know of for the symbols that don't defeat the purpose
 of making a nice clean EDSL for expressions; I might as well use 3*X +
 Y `lessthan` 3, which is just not cool.
 
 Does anyone know of a good solution, here?  Are there good
 substitutions for all the six operators that are important
 (,,=,=,==,/=), that are close enough to be pretty-looking but not
 used for other important modules?
 
 Better yet, though a little harder, is there a nice type trick I'm not
 thinking of?  This works for Num methods but not for Ord methods
 because:
 
 (+) :: (Num a) = a - a - a
 () :: (Ord a) = a - a - Bool
 
 i.e. the return type of comparisons is totally fixed.  I don't suppose
 there's a good way to...well, I don't know what the *right* answer is,
 but maybe define a new typeclass with a more flexible type for  that
 lets both standard types return Bool and my expressions return Expr?
 Any good solution would be appreciated.
 
 Thanks,
 AHH
 ___
 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] Does anybody dislike implicit params as much asI do?

2009-03-13 Thread Sittampalam, Ganesh
Jules Bean wrote:
 Thomas Hartman wrote:

http://blog.patch-tag.com/2009/03/09/implicitparams-are-evil-thoughts-
 on-adapting-gitit/ 
 
 I understand there are arguments for using IPs, but after this
 experience, the ImplicitParams extension is a code smell for me.
 
 It's not just you. Implicit parameters are a scourge on the language.

I think they have a useful place in propagating semi-global
configuration
information without imposing huge syntactic overhead. I think using them
like
in the code referred to in the URL above, where their values are
frequently
changed down the call stack, is dangerous.

Ganesh

=== 
 Please access the attached hyperlink for an important electronic 
communications disclaimer: 
 http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html 
 
=== 
 
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Against cuteness

2009-03-13 Thread Gregg Reynolds
On Thu, Mar 12, 2009 at 9:17 PM, Benjamin L. Russell
dekudekup...@yahoo.com wrote:
 On Thu, 12 Mar 2009 09:11:15 -0500, Gregg Reynolds d...@mobileink.com
 wrote:

I don't think so.  Bad design will lose them (and many others), but
good design and cuteness are two different things.

 It's also possible for a good design to be cute, too.


De cutibus non est disputandem.

Personally I think something interesting could be done with Thoth
(nice open svg image at http://en.wikipedia.org/wiki/Thoth):  God of
reading/writing, math.  When conflated with Hermes, also of
boundaries, thieves and scoundrels, etc.

Then there's Haskell B. Curry himself; notice the resemblance
(http://www.haskell.org/bio.html) with J. R. Bob Dobbs
(http://en.wikipedia.org/wiki/J._R._%22Bob%22_Dobbs).  An artist could
comicize an image of Curry.  Then it's only a short step to actual
cultdom - why stop with a mere web community when you can legally
establish a religious cult and actually ordain Ministers?
(http://www.subgenius.com/scatalog/membership.htm).

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


Re: [Haskell-cafe] Re: Sugestion for a Haskell mascot

2009-03-13 Thread Sjur Gjøstein Karevoll
I've unconciously conditioned myself to think about rabbits with nukes each 
time I think about monads. Warm fuzzy things launching the missiles 
indeed.

On Friday 13 March 2009 02.38.29 Richard O'Keefe wrote:
 On 12 Mar 2009, at 11:08 pm, Satnam Singh wrote:
  I agree that looking for a mascot that is inspired by laziness is
  a bad idea from a P.R. perspective (I am tired of people walking out
  the room when I give Haskell talks to general audiences and explain
  lazy evaluation).

 Perhaps we should call it Just-In-Time evaluation.

 As for mascots, let's take a photo of Simon Peyton Jones,
 shrink him to hobbit size, give him furry feet, and announce
 that here is one of the warm fuzzy things we have in mind
 when we use monads.  (:-)

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

-- 
Sjur Gjøstein Karevoll
sjurberen...@gmail.com
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Applicative combinators from Parsec

2009-03-13 Thread Martijn van Steenbergen

Hello,

Looking at Parsec 3 I see:


chainr1 :: (Stream s m t) = ParsecT s u m a -
   ParsecT s u m (a - a - a) - ParsecT s u m a
chainr1 p op = scan where
  scan = do x - p; rest x
  rest x = (do f - op; y - scan; return (f x y)) | return x



But if I remove the type signature and let GHC infer it for me, I get a 
much more generic type:



chainr1 :: (Alternative m, Monad m) = m a - m (a - a - a) - m a


But we don't really need m to be a monad since we're only doing 
applicative operations, so after some rewriting we get:



chainr1 :: Alternative f = f a - f (a - a - a) - f a
chainr1 p op = scan where
  scan = flip id $ p * rest
  rest = (flip $ op * scan) | pure id


Would it be a good idea to:
1) make the Parsec combinators as generic as possible and
2) move the really generic applicative ones to Control.Applicative?

Thanks,

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


[Haskell-cafe] Re: Against cuteness

2009-03-13 Thread Benjamin L . Russell
On Fri, 13 Mar 2009 12:29:25 +0100, Achim Schneider bars...@web.de
wrote:

Benjamin L.Russell dekudekup...@yahoo.com wrote:

 balance

Stop right there. Any further word about what the Taiji means would
only make you look even more clueless. Take a scale if you want a
symbol for balance[1].

Granted, I'm no expert on Taoism, so I am not qualified to comment on
the meaning of the Taiji.  Rather, I was merely trying to assign
meaning to a symbol that resembled the Taiji, but not to interpret the
Taiji itself.

OTOH, laziness(yin) and strictness(yang) make a far better pair of
unified opposites than the schemeish eval and apply (which's outer
essences are both yang, changing to yin only by means of what they
execute[2]).

Indeed.  But strictness would not characterize Haskell, would it?

Still, you wouldn't represent the Maybe monad with =, now would you?
Instantiating a symbol for a general principle to whatever you like
constitutes pocketing.

Indeed.  The symbol would need to be modified and distinguished
appropriately.

Anyway, I think it's too late for logo submissions. Personally, I just
love the lambda-bind, it's truly haskellish, sleek, appropriately
cryptic and lends itself well to ascii-art.

Agreed.

What about a chicken holding a curry dispenser? In any case, I don't
think a sloth is a bad choice as a mascot: It's most likely the most
efficient animal on earth, and seeing it, you're bound to be mystified
how it manages to get anything done.

It's indeed efficient, but also slow; while Schemers are accused of
knowing the value of everything, but the cost of nothing, a sloth
mascot could cause Haskellers to become accused of knowing the
efficiency of everything, but the speed of nothing, no?

Water overcomes stone:
Shapeless, it requires no opening:
The benefit of taking no action.

Yet benefit without action,
And experience without abstraction,
Are practiced by very few.

Nice poem.  Did you write it yourself, or can you document the source?

-- Benjamin L. Russell
-- 
Benjamin L. Russell  /   DekuDekuplex at Yahoo dot com
http://dekudekuplex.wordpress.com/
Translator/Interpreter / Mobile:  +011 81 80-3603-6725
Furuike ya, kawazu tobikomu mizu no oto. 
-- Matsuo Basho^ 

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


Re: [Haskell-cafe] Re: Against cuteness

2009-03-13 Thread Alex Queiroz
Hallo,

On Fri, Mar 13, 2009 at 1:23 PM, Benjamin L. Russell
dekudekup...@yahoo.com wrote:
 On Fri, 13 Mar 2009 12:29:25 +0100, Achim Schneider bars...@web.de

Water overcomes stone:
Shapeless, it requires no opening:
The benefit of taking no action.

Yet benefit without action,
And experience without abstraction,
Are practiced by very few.

 Nice poem.  Did you write it yourself, or can you document the source?


 If I remember correctly, this is from the Daodejing.

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


Re: [Haskell-cafe] Applicative combinators from Parsec

2009-03-13 Thread andy morris
2009/3/13 Martijn van Steenbergen mart...@van.steenbergen.nl:
 Hello,

 Looking at Parsec 3 I see:

 chainr1 :: (Stream s m t) = ParsecT s u m a -
           ParsecT s u m (a - a - a) - ParsecT s u m a
 chainr1 p op = scan where
  scan = do x - p; rest x
  rest x = (do f - op; y - scan; return (f x y)) | return x


 But if I remove the type signature and let GHC infer it for me, I get a much
 more generic type:

 chainr1 :: (Alternative m, Monad m) = m a - m (a - a - a) - m a

 But we don't really need m to be a monad since we're only doing applicative
 operations, so after some rewriting we get:

 chainr1 :: Alternative f = f a - f (a - a - a) - f a
 chainr1 p op = scan where
  scan = flip id $ p * rest
  rest = (flip $ op * scan) | pure id

 Would it be a good idea to:
 1) make the Parsec combinators as generic as possible and
 2) move the really generic applicative ones to Control.Applicative?

 Thanks,

 Martijn.

This reminds me of something similar I find a bit annoying:

There are some functions like (|) which are defined separately in
Text.Parsec and Control.Applicative, meaning that you have to hide one
of the sets. Would it be better perhaps to just have Parsec reexport
the existing functions from Applicative, or something like that?

(Currently the functions in Parsec have the more specific type as
Martijn says, but if they're generalised then I don't really see why
they need to be duplicated.)
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] bytestring vs. uvector

2009-03-13 Thread Manlio Perillo

Don Stewart ha scritto:

[...]

I think uvector only works with certain types that can be
unboxed, while storablevector works with all types that
instantiate Foreign.Storable.Storable.  I don't know about
vector.  From the description of vector, I have the




One of the nice feature of uvector is the support for UArr (a :*: b).

An UArr (a :*: b) can be easily (with fstU and sndU) transformed in
UArr a and UArr b.

uvector package also suppors Complex and Rational, however the support 
for these type is hard written, using a UAProd class, and requires 
some boiler plate code (IMHO).


I find StorableVector implementation much more simple; I would like to 
see it in the Haskell Platform.


As for Data.Parallel, uvector and vector, it seems there is some code 
duplication.


Both Data.Parallel and uvector, make us of a strict pair type.
Such a type is also implemented in the strict package [1].

The authors are the same, so I don't understand the reason of code 
replication.



There is also replication in the definition of the Stream data type.



[1] there seems to be an error in the documentation:
http://hackage.haskell.org/packages/archive/strict/0.3.2/doc/html/Data-Strict-Tuple.html

In the description, there is:
Same as regular Haskell pairs, but (x :*: _|_) = (_|_ :*: y) = _|_

but in the synopsis, the data constructor is :!:, not :*:.



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


Re: [Haskell-cafe] Re: Sugestion for a Haskell mascot

2009-03-13 Thread Roel van Dijk
What about the Rabbit of Caerbannog[1]. Looks cute on first sight,
but upon further investigation turns out to be a vicious killer.
Useful to quench any rumors of Haskell being a toy language. You just
need to look a bit closer.


[1] http://en.wikipedia.org/wiki/Rabbit_of_Caerbannog

On Fri, Mar 13, 2009 at 1:29 PM, Sjur Gjøstein Karevoll
sjurberen...@gmail.com wrote:
 I've unconciously conditioned myself to think about rabbits with nukes each
 time I think about monads. Warm fuzzy things launching the missiles
 indeed.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Pointless functors

2009-03-13 Thread Martijn van Steenbergen

Bonjour café,

Are there any functors f for which no point/pure/return :: a - f a exists?

Thank you,

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


Re: [Haskell-cafe] bytestring vs. uvector

2009-03-13 Thread Manlio Perillo

Don Stewart ha scritto:

bulat.ziganshin:

Hello Don,

Wednesday, March 11, 2009, 12:12:07 AM, you wrote:


Right, so my point stands: there's no difference now. If you can write a
Storable instance, you can write a UA et al instance.

yes, if there is some class provided for this and not just hard-coded
4 or so base types 


That's right. For example (supporting even pairs):

instance (RealFloat a, UA a) = UA (Complex a) where

  newtype UArr  (Complex a)   = UAComplex  (UArr (a :*: a))
  newtype MUArr (Complex a) s = MUAComplex (MUArr (a :*: a) s)



You also have to add instance for UIO:

instance (RealFloat a, UIO a) = UIO (Complex a) where
hPutU h (UAComplex arr) = hPutU h arr
hGetU h = do arr - hGetU h
 return (UAComplex arr)


With Storable, this should not be required; you just have to write an 
instance for the Storable class.




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


[Haskell-cafe] Vim support for cabal

2009-03-13 Thread Pavel Perikov

Hi café !

I googled for some kind of vim support for  cabal but found nothing. I  
mean syntax highlighting of .cabal and probably integration with  
haskellmode. Did anyone hear about such thing?


Pavel

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


[Haskell-cafe] Re: Against cuteness

2009-03-13 Thread Achim Schneider
Benjamin L.Russell dekudekup...@yahoo.com wrote:

 OTOH, laziness(yin) and strictness(yang) make a far better pair of
 unified opposites than the schemeish eval and apply (which's outer
 essences are both yang, changing to yin only by means of what they
 execute[2]).
 
 Indeed.  But strictness would not characterize Haskell, would it?
 
Not by itself, no. But Haskell, as a language that's neither strict nor
lazy, but non-strict (and can therefore combine eagerness and laziness)
is closer to the Tao of execution than any purely strict or purely
lazy language. One, after all, cannot be without the other: Both are
not separate, but distinguished only by our perception.

 What about a chicken holding a curry dispenser? In any case, I don't
 think a sloth is a bad choice as a mascot: It's most likely the most
 efficient animal on earth, and seeing it, you're bound to be
 mystified how it manages to get anything done.
 
 It's indeed efficient, but also slow; while Schemers are accused of
 knowing the value of everything, but the cost of nothing, a sloth
 mascot could cause Haskellers to become accused of knowing the
 efficiency of everything, but the speed of nothing, no?

I'd say we know the necessity of everything, but the schedule of
nothing.

...the point I'm trying to make here is that the appearance of
swiftness is not everything: A tight loop executing nop's may seem
busy, but won't tell you much interesting stuff.

Imagine a cute sloth peeking out of a PC case, together with Lazy bum
is executeing ur prugram, but only half of it


 Water overcomes stone:
 Shapeless, it requires no opening:
 The benefit of taking no action.
 
 Yet benefit without action,
 And experience without abstraction,
 Are practiced by very few.
 
 Nice poem.  Did you write it yourself, or can you document the source?
 
It's out of the Tao te Ching, by, allegedly, Lao Tzu. It hints at
Wuwei[1], or, from another angle, Kant's Categorical Imperative.


[1]http://en.wikipedia.org/wiki/Wu_wei

-- 
(c) this sig last receiving data processing entity. Inspect headers
for copyright history. All rights reserved. Copying, hiring, renting,
performance and/or quoting of this signature prohibited.


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


[Haskell-cafe] Re: Sugestion for a Haskell mascot

2009-03-13 Thread Achim Schneider
Roel van Dijk vandijk.r...@gmail.com wrote:

 What about the Rabbit of Caerbannog[1]. Looks cute on first sight,
 but upon further investigation turns out to be a vicious killer.
 Useful to quench any rumors of Haskell being a toy language. You just
 need to look a bit closer.
 
 
 [1] http://en.wikipedia.org/wiki/Rabbit_of_Caerbannog
 
Is that, in some way, connected to those cute christmas critters Erik
[afair] thought of that keep creeping the hell out of everyone in
Imaginationland?

(I guess I watched too much Southpark)



-- 
(c) this sig last receiving data processing entity. Inspect headers
for copyright history. All rights reserved. Copying, hiring, renting,
performance and/or quoting of this signature prohibited.


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


Re: [Haskell-cafe] Pointless functors

2009-03-13 Thread Ross Paterson
On Fri, Mar 13, 2009 at 03:18:15PM +0100, Martijn van Steenbergen wrote:
 Are there any functors f for which no point/pure/return :: a - f a exists?

No.  Choose an arbitrary element shape :: f () and define

point x = fmap (const x) shape
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Pointless functors

2009-03-13 Thread Eugene Kirpichov
'An arbitrary element' means 'undefined will suffice'

point x = fmap (const x) undefined


2009/3/13 Ross Paterson r...@soi.city.ac.uk:
 On Fri, Mar 13, 2009 at 03:18:15PM +0100, Martijn van Steenbergen wrote:
 Are there any functors f for which no point/pure/return :: a - f a exists?

 No.  Choose an arbitrary element shape :: f () and define

        point x = fmap (const x) shape
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe




-- 
Eugene Kirpichov
Web IR developer, market.yandex.ru
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] bytestring vs. uvector

2009-03-13 Thread Manlio Perillo

Manlio Perillo ha scritto:

[...]
uvector package also suppors Complex and Rational, however the support 
for these type is hard written, using a UAProd class, and requires 
some boiler plate code (IMHO).




Correction: UAProd is not a class, sorry.
It is the UA constructor overloaded for a:*:b, and Complex and Rational 
just reuse this specialization.



 [...]


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


Re: [Haskell-cafe] Pointless functors

2009-03-13 Thread Conor McBride


On 13 Mar 2009, at 14:32, Ross Paterson wrote:

On Fri, Mar 13, 2009 at 03:18:15PM +0100, Martijn van Steenbergen  
wrote:
Are there any functors f for which no point/pure/return :: a - f a  
exists?


No.  Choose an arbitrary element shape :: f () and define

   point x = fmap (const x) shape


Correspondingly, consider the functor Const Void.

Cheers

Conor

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


Re: [Haskell-cafe] Dynamically typing TH.Exp at runtime

2009-03-13 Thread Brandon S. Allbery KF8NH

On 2009 Mar 13, at 4:03, Martin Hofmann wrote:
That's true, inferring the type of a string is not the problem.  
However,
I am not only interested in the top-level type, but also in the type  
of

any arbitrary subexpression. Consider for example following recursive
definition:


I'm pretty sure you can pull a typed AST out of ghc-api and query the  
type of any node.


--
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allb...@kf8nh.com
system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu
electrical and computer engineering, carnegie mellon universityKF8NH




PGP.sig
Description: This is a digitally signed message part
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Pointless functors

2009-03-13 Thread Brent Yorgey
On Fri, Mar 13, 2009 at 02:32:23PM +, Ross Paterson wrote:
 On Fri, Mar 13, 2009 at 03:18:15PM +0100, Martijn van Steenbergen wrote:
  Are there any functors f for which no point/pure/return :: a - f a exists?
 
 No.  Choose an arbitrary element shape :: f () and define
 
 point x = fmap (const x) shape

But since f may be polymorphic in some other types, it may not be
possible to choose such an arbitrary shape.  For example, ((,) w) is a
Functor but it is not possible to define a function point :: a -
(w,a) without (1) using undefined for the value of type w, or (2)
putting some sort of constraint on w which lets us choose a canonical
value of type w, such as Monoid.

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


Re: [Haskell-cafe] ANNOUNCE: Vintage BASIC 1.0

2009-03-13 Thread Lyle Kopnicky
On Fri, Mar 13, 2009 at 1:31 AM, Wolfgang Jeltsch 
jelt...@informatik.tu-cottbus.de wrote:

 When running the executable, nothing happens. The executable should show a
 usage message instead. Where are the BASIC programs? I think, you have to
 grab them from the source. They should be installed, too.


Thanks for your feedback, and for checking out Vintage BASIC!

I will add a usage message, as you suggested. Currently the usage is only
described in the User's Guide. There are no options; you just give it the
name of one or more BASIC source files. (Naturally this extends to doing
nothing when supplied with zero source files.)

The BASIC games are at http://www.vintage-basic.net/games.html. There is a
tarball of all the games
(bcg.tar.gzhttp://www.vintage-basic.net/downloads/bcg.tar.gz)
as well. These are separated from the Vintage BASIC distribution for legal
reasons. Vintage BASIC is copyrighted by me under a BSD license. The games
were written by many authors and compiled into a book copyrighted by
Creative Computing. I have secured permission from the editor to post the
games. I do not wish to imply that they are covered by the same license as
the interpreter. If anyone has any suggestions as to how to make the process
simpler, I'd be happy to hear it.

Thanks,
Lyle

P.S. I need to get my other e-mail account subscribed to this list
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Pointless functors

2009-03-13 Thread Martijn van Steenbergen

Eugene Kirpichov wrote:

'An arbitrary element' means 'undefined will suffice'

point x = fmap (const x) undefined


Prelude fmap (const True) undefined :: [Bool]
*** Exception: Prelude.undefined

Or is that not what you mean?

Martijn.

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


Re: [Haskell-cafe] Pointless functors

2009-03-13 Thread Brent Yorgey
On Fri, Mar 13, 2009 at 05:35:31PM +0300, Eugene Kirpichov wrote:
 'An arbitrary element' means 'undefined will suffice'
 
 point x = fmap (const x) undefined

This is false.

  Prelude fmap (const 1) [()]
  [1]
  Prelude fmap (const 1) undefined
  *** Exception: Prelude.undefined

-Brent

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


Re: [Haskell-cafe] Natural Numbers: Best implementation?

2009-03-13 Thread Brandon S. Allbery KF8NH

On 2009 Mar 13, at 4:25, Wolfgang Jeltsch wrote:

Am Freitag, 13. März 2009 04:53 schrieb Brandon S. Allbery KF8NH:

On 2009 Mar 12, at 22:54, Mark Spezzano wrote:

I was wondering what the best way to implement Natural number would
be. Is there a package which already does this?


type-level on Hackage.


I think, the original poster wanted value-level naturals, not type- 
level

naturals.


My (possibly incorrect) understanding was that value-level naturals  
required runtime range checks, whereas type-level naturals allowed you  
to validate them at compile time.  I thought I'd mentioned that in my  
response, contrasting type-level naturals with value-level newtypes  
and other implementations.


--
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allb...@kf8nh.com
system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu
electrical and computer engineering, carnegie mellon universityKF8NH




PGP.sig
Description: This is a digitally signed message part
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Applicative combinators from Parsec

2009-03-13 Thread Brandon S. Allbery KF8NH

On 2009 Mar 13, at 9:57, andy morris wrote:

(Currently the functions in Parsec have the more specific type as
Martijn says, but if they're generalised then I don't really see why
they need to be duplicated.)



Possibly so Parsec has decent performance on Haskell compilers that  
don't do {-# SPECIALIZE #-}?


--
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allb...@kf8nh.com
system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu
electrical and computer engineering, carnegie mellon universityKF8NH




PGP.sig
Description: This is a digitally signed message part
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Pointless functors

2009-03-13 Thread Robin Green
For most functors, that is equivalent to

point x = undefined

But by that logic, everything is a member of every typeclass...
-- 
Robin

On Fri, 13 Mar 2009 17:35:31 +0300
Eugene Kirpichov ekirpic...@gmail.com wrote:

 'An arbitrary element' means 'undefined will suffice'
 
 point x = fmap (const x) undefined
 
 
 2009/3/13 Ross Paterson r...@soi.city.ac.uk:
  On Fri, Mar 13, 2009 at 03:18:15PM +0100, Martijn van Steenbergen
  wrote:
  Are there any functors f for which no point/pure/return :: a - f
  a exists?
 
  No.  Choose an arbitrary element shape :: f () and define
 
         point x = fmap (const x) shape
  ___
  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] Pointless functors

2009-03-13 Thread Robin Green
On Fri, 13 Mar 2009 14:32:23 +
Ross Paterson r...@soi.city.ac.uk wrote:

 On Fri, Mar 13, 2009 at 03:18:15PM +0100, Martijn van Steenbergen
 wrote:
  Are there any functors f for which no point/pure/return :: a - f a
  exists?
 
 No.  Choose an arbitrary element shape :: f () and define
 
 point x = fmap (const x) shape

This suggests a fun way to define a monad for a functor F:

-- Does nothing, has no effect, and returns ()
noOp :: F ()
noOp = ...

instance Monad F where
  return x = fmap (const x) noOp
  (=) f x = ...

I think noOp would be a nice addition to the Monad class, as well.
-- 
Robin
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Pointless functors

2009-03-13 Thread Eugene Kirpichov
Well, yes; then, that means that an arbitrary element is also false:
you can't just take an arbitrary element and hope that works well.

Then the original question must be reformulated:
 - Are there any functors for which there exists at least one
non-bottom value of type 'f a' for some a, but there does not exist a
function point :: a - f a such that (a != _|_) = (point a != _|_).



2009/3/13 Brent Yorgey byor...@seas.upenn.edu:
 On Fri, Mar 13, 2009 at 05:35:31PM +0300, Eugene Kirpichov wrote:
 'An arbitrary element' means 'undefined will suffice'

 point x = fmap (const x) undefined

 This is false.

  Prelude fmap (const 1) [()]
  [1]
  Prelude fmap (const 1) undefined
  *** Exception: Prelude.undefined

 -Brent

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




-- 
Eugene Kirpichov
Web IR developer, market.yandex.ru
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Using a monad to decompose a function into functions

2009-03-13 Thread Cristiano Paris
2009/3/13 Marcin Kosiba marcin.kos...@gmail.com:
 ...
 Threading the state is not the problem. Maybe this will help:
 what I have now:

 fsm world state = case state of
  first -
    do_stuff_one
    (move_up, succ state)
  second -
    do_stuff_two
    (move_left, succ state)
  third -
     do_stuff_three
     (move_right, first)

 what I'd want to have is to say:
 fsm world state = do
  do_stuff_one
  yield move_up
  do_stuff_two
  yield move_left
  do_stuff_three
  yield move_right
  fsm world state

 and have it translated to:

 fsm world state =
  do_stuff_one
  (move_up, \world' state' -
    do_stuff_two
      (move_left, \world'' state'' -
         do_stuff_three
           (move_right, fsm world'' state'')

Hi,

I've not fully understood your exact problem but I think you might
have a look to Continuations and Delimited Continuations.

Both can help you solve the problem with implementing a yield
statement. You can have a look at one of my (rather) old blog's posts
about how to implement yield/send statements a-la-python:

http://monadicheadaches.blogspot.com/2008/01/python-25s-iterators-in-haskell-sort-of.html

Notice that blogspot messed up with code blocks so indentation looks
bad and some character is even missing.

Bye,

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


Re: [Haskell-cafe] Pointless functors

2009-03-13 Thread Dan Doel
On Thursday 12 March 2009 10:30:47 pm Robin Green wrote:
 For most functors, that is equivalent to

 point x = undefined

 But by that logic, everything is a member of every typeclass...

There are some cases where expected laws will prevent that. For instance, If 
you try to make a monad like:

  instance Monad m where
return  = undefined
m = f = undefined

Then it will fail the law:

  m = return = m

unless the only possible value of m is undefined (that is, m a is uninhabited 
except for bottom).

In the case of pointed functors, the point is supposed to be a natural 
transformation from the identity functor to the functor in question, so:

  fmap f . point = point . f

which always works with 'point = undefined' as long as 'fmap f' is strict 
(which it's basically required to be, since it must satisfy fmap id = id, and 
id is strict).

Of course, the fact that it satisfies the relevant law doesn't make it less 
worthless as an instance. To make things less trivial, one might restrict 
himself to definitions that would work in a total language, and then it's easy 
to come up with examples of functors that aren't pointed. For instance, one 
can write the following in Agda:

  data Void (a : Set) : Set where -- empty

  mapVoid : {a b : Set} - (a - b) - Void a - Void b
  mapVoid f ()  -- empty function

  pointVoid : {a : Set} - a - Void a
  pointVoid = ? -- can't be written

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


Re: [Haskell-cafe] Pointless functors

2009-03-13 Thread Ross Paterson
On Fri, Mar 13, 2009 at 04:11:57PM +0100, Martijn van Steenbergen wrote:
 Eugene Kirpichov wrote:
 'An arbitrary element' means 'undefined will suffice'

 point x = fmap (const x) undefined

 Prelude fmap (const True) undefined :: [Bool]
 *** Exception: Prelude.undefined

 Or is that not what you mean?

OK, an arbitrary maximal element.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] How to get a typed (type tagged) AST from GHC's core [Was: Dynamically typing TH.Exp at runtime]

2009-03-13 Thread Martin Hofmann
Brandon S. Allbery KF8NH wrote:
 I'm pretty sure you can pull a typed AST out of ghc-api and query the  
 type of any node.

Thanks. I am relieved to hear that.

Could anybody tell me, where to start in the ghc-api? It's pretty hard,
when you don't know where to look. Hoogle doesn't know anything about
it. I found following DT describing the core language, but as far as I
see, there are no type in there either.

http://www.haskell.org/ghc/docs/latest/html/libraries/ghc/CoreSyn.html#t
%3AExpr
  


Thanks a lot,

Martin

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


Re: [Haskell-cafe] Pointless functors

2009-03-13 Thread Matthew Brecknell
Ross Paterson wrote: 
 No.  Choose an arbitrary element shape :: f () and define
point x = fmap (const x) shape

Interesting. Is the arbitrariness of the shape some sort of evidence
that Pointed is not really a very useful class in its own right?

Certainly, the shape does matter if you plan to progress to non-trivial
Applicative or Monad instances. For example, the non-determinism monad
requires shape = [()], while the ZipList applicative functor requires
shape = repeat ().

Eugene Kirpichov wrote:
 'An arbitrary element' means 'undefined will suffice'
 point x = fmap (const x) undefined

Well, that would rather limit the possible Applicative instances. :-)

(Consider the Applicative law: fmap g x = pure g * x)

Brent Yorgey wrote:
 Prelude fmap (const 1) [()]
 [1]
 Prelude fmap (const 1) undefined
 *** Exception: Prelude.undefined

True, but as far as I can tell, that doesn't violate any laws of the
Pointed class. To put it crudely, if [] is as good as [()], then how is
undefined any worse?



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


Re: [Haskell-cafe] Pointless functors

2009-03-13 Thread Jonathan Cast
On Sat, 2009-03-14 at 02:12 +1000, Matthew Brecknell wrote:
 Ross Paterson wrote: 
  No.  Choose an arbitrary element shape :: f () and define
 point x = fmap (const x) shape
 
 Interesting. Is the arbitrariness of the shape some sort of evidence
 that Pointed is not really a very useful class in its own right?

A simpler bit of evidence is that the only law I can think of for point
(in its own right) is

  fmap f . point = point . f

which we get free anyway.

jcc


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


Re: [Haskell-cafe] Pointless functors

2009-03-13 Thread Ross Paterson
On Sat, Mar 14, 2009 at 02:12:45AM +1000, Matthew Brecknell wrote:
 Ross Paterson wrote: 
  No.  Choose an arbitrary element shape :: f () and define
 point x = fmap (const x) shape
 
 Interesting. Is the arbitrariness of the shape some sort of evidence
 that Pointed is not really a very useful class in its own right?

Not useless, but equivalent to

  class Functor f = Pointed f where
unit :: f ()

Naturality of point does the rest.  But not all definitions of unit
are equally useful.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] bytestring vs. uvector

2009-03-13 Thread Don Stewart
manlio_perillo:
 Don Stewart ha scritto:
 bulat.ziganshin:
 Hello Don,

 Wednesday, March 11, 2009, 12:12:07 AM, you wrote:

 Right, so my point stands: there's no difference now. If you can write a
 Storable instance, you can write a UA et al instance.
 yes, if there is some class provided for this and not just hard-coded
 4 or so base types 

 That's right. For example (supporting even pairs):

 instance (RealFloat a, UA a) = UA (Complex a) where

   newtype UArr  (Complex a)   = UAComplex  (UArr (a :*: a))
   newtype MUArr (Complex a) s = MUAComplex (MUArr (a :*: a) s)


 You also have to add instance for UIO:

 instance (RealFloat a, UIO a) = UIO (Complex a) where
 hPutU h (UAComplex arr) = hPutU h arr
 hGetU h = do arr - hGetU h
  return (UAComplex arr)


 With Storable, this should not be required; you just have to write an  
 instance for the Storable class.




Though you get no IO operations with Storable... UIO is entirely
separate.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Combining haddock documentation from multiple packages

2009-03-13 Thread Heikki Aitakangas
Is it possible to generate a unified documentation tree similar to 
http://www.haskell.org/ghc/docs/latest/html/libraries/index.html from 
packages installed via cabal from hackage? And if so, how does one go 
about doing it?



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


Re: [Haskell-cafe] Using a monad to decompose a function into functions

2009-03-13 Thread Marcin Kosiba
On Friday 13 March 2009, Cristiano Paris wrote:
 2009/3/13 Marcin Kosiba marcin.kos...@gmail.com:
  ...
  Threading the state is not the problem. Maybe this will help:
  what I have now:
 
  fsm world state = case state of
   first -
     do_stuff_one
     (move_up, succ state)
   second -
     do_stuff_two
     (move_left, succ state)
   third -
      do_stuff_three
      (move_right, first)
 
  what I'd want to have is to say:
  fsm world state = do
   do_stuff_one
   yield move_up
   do_stuff_two
   yield move_left
   do_stuff_three
   yield move_right
   fsm world state
 
  and have it translated to:
 
  fsm world state =
   do_stuff_one
   (move_up, \world' state' -
     do_stuff_two
       (move_left, \world'' state'' -
          do_stuff_three
            (move_right, fsm world'' state'')

 Hi,

 I've not fully understood your exact problem but I think you might
 have a look to Continuations and Delimited Continuations.

 Both can help you solve the problem with implementing a yield
 statement. You can have a look at one of my (rather) old blog's posts
 about how to implement yield/send statements a-la-python:

 http://monadicheadaches.blogspot.com/2008/01/python-25s-iterators-in-haskel
l-sort-of.html

 Notice that blogspot messed up with code blocks so indentation looks
 bad and some character is even missing.

Hi,
I've already checked those out. I tried using your yield implementation 
and 
while it works, I couldn't get it to work with the state monad.
So while:
data RecPair a b = Nil | RP (b, a - RecPair a b)
yield x = Cont $ \k - RP (x, k)

got me half-way to my goal, I couldn't figure out how to make something 
like:

yield' = do
  state - get
  state' - yield state
  put state'

Thanks!
Marcin Kosiba


signature.asc
Description: This is a digitally signed message part.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] How to get a typed (type tagged) AST from GHC's core [Was: Dynamically typing TH.Exp at runtime]

2009-03-13 Thread Matthijs Kooijman
Hi Martin,

 Could anybody tell me, where to start in the ghc-api? It's pretty hard,
 when you don't know where to look. Hoogle doesn't know anything about
 it. I found following DT describing the core language, but as far as I
 see, there are no type in there either.
I've been working on parsing core in the past few months. For an example, look
here:
  
http://git.stderr.nl/gitweb?p=matthijs/projects/fhdl.git;a=blob;f=Translator.hs;h=8072f85925ad1238

The loadModule and findBind functions are interesting. As for iterating the
AST, have a look at Flatten.hs.

Good luck, any questions are welcome!

Gr.

Matthijs


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


Re: [Haskell-cafe] bytestring vs. uvector

2009-03-13 Thread Manlio Perillo

Don Stewart ha scritto:

[...]

You also have to add instance for UIO:

instance (RealFloat a, UIO a) = UIO (Complex a) where
hPutU h (UAComplex arr) = hPutU h arr
hGetU h = do arr - hGetU h
 return (UAComplex arr)


With Storable, this should not be required; you just have to write an  
instance for the Storable class.




Though you get no IO operations with Storable... UIO is entirely
separate.



Yes, but using Storable and Foreign.Ptr, IO is rather simple.
From storablevector package:

-- | Outputs a 'Vector' to the specified 'Handle'.
hPut :: (Storable a) = Handle - Vector a - IO ()
hPut h v =
   if null v
 then return ()
 else
   let (fptr, s, l) = toForeignPtr v
   in  withForeignPtr fptr $ \ ptr -
  let ptrS = advancePtr ptr s
  ptrE = advancePtr ptrS l
  -- use advancePtr and minusPtr in order to respect
  -- alignment
  in  hPutBuf h ptrS (minusPtr ptrE ptrS)

-- | Read a 'Vector' directly from the specified 'Handle'.  This
-- is far more efficient than reading the characters into a list
-- and then using 'pack'.
--
hGet :: (Storable a) = Handle - Int - IO (Vector a)
hGet _ 0 = return empty
hGet h i =
   createAndTrim i $ \p -
  let elemType :: Ptr a - a
  elemType _ = undefined
  sizeOfElem = sizeOf (elemType p)
  in  fmap (flip div sizeOfElem) $
  hGetBuf h p (i * sizeOfElem)


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


Re: [Haskell-cafe] bytestring vs. uvector

2009-03-13 Thread Manlio Perillo

Bryan O'Sullivan ha scritto:

[...]
text is not mature, and is based on the same modern fusion framework as 
uvector and vector. It uses unpinned arrays, but provides functions for 
dealing with foreign code. 


What is the reason why you have decided to use unpinned arrays 
(ByteArray#) instead of pinned arrays (Foreign.Ptr)?



 [...]



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


Re: [Haskell-cafe] bytestring vs. uvector

2009-03-13 Thread Don Stewart
manlio_perillo:
 Bryan O'Sullivan ha scritto:
 [...]
 text is not mature, and is based on the same modern fusion framework as 
 uvector and vector. It uses unpinned arrays, but provides functions for 
 dealing with foreign code. 

 What is the reason why you have decided to use unpinned arrays  
 (ByteArray#) instead of pinned arrays (Foreign.Ptr)?

They prevent heap fragmentation (and in general are faster).

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


Re: [Haskell-cafe] Has anybody replicated =~ s/../../ or even something more basic for doing replacements with pcre haskell regexen?

2009-03-13 Thread Don Stewart
tphyahoo:
 Is there something like subRegex... something like =~ s/.../.../ in
 perl... for haskell pcre Regexen?
 
 I mean, subRegex from Text.Regex of course:
 http://hackage.haskell.org/cgi-bin/hackage-scripts/package/regex-compat
 
 Thanks for any advice,

Basically, we should have it.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Using a monad to decompose a function into functions

2009-03-13 Thread David Menendez
2009/3/13 Marcin Kosiba marcin.kos...@gmail.com:

 Threading the state is not the problem. Maybe this will help:
 what I have now:

 fsm world state = case state of
  first -
    do_stuff_one
    (move_up, succ state)
  second -
    do_stuff_two
    (move_left, succ state)
  third -
     do_stuff_three
     (move_right, first)

 what I'd want to have is to say:
 fsm world state = do
  do_stuff_one
  yield move_up
  do_stuff_two
  yield move_left
  do_stuff_three
  yield move_right
  fsm world state

 and have it translated to:

 fsm world state =
  do_stuff_one
  (move_up, \world' state' -
    do_stuff_two
      (move_left, \world'' state'' -
         do_stuff_three
           (move_right, fsm world'' state'')

Do you really need yield? Most of the time, you should be able to
implement move_up and the rest directly using bits of the run
function.

But assuming you do need yield, you probably want a resumption monad.
Here's a variant of an implementation I've worked with recently.

data Thunk r m a = Val a | Suspend r (m (Thunk r m a))

newtype Suspend r m a = C { unC :: forall b. (a - m (Thunk r m a)) -
m (Thunk r m a) }

instance Monad (Suspend r m) where
return a = C (\k - k a)
m = f = C (\k - unC m (\a - unC (f a) k))

instance MonadTrans (Suspend r) where
lift m = C (\k - m = k)

suspend :: Monad m = r - Suspend r m ()
suspend r = C (\k - return $ Suspend r (k ()))

run :: Monad m = Suspend r m a - m (Thunk r m a)
run m = unC m (return . Val)


These laws should give an idea of how it works:

run (return a) = return (Val a)
run (lift m = f) = m = \a - run (f a)
run (suspend r  m) = return (Suspend r (run m))


There's also a function that undoes run, although you shouldn't need it.

enter :: Monad m = Thunk r m a - Suspend r m a
enter (Val a) = return a
enter (Suspend r m) = suspend r  lift m = enter

-- 
Dave Menendez d...@zednenem.com
http://www.eyrie.org/~zednenem/
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re[2]: [Haskell-cafe] bytestring vs. uvector

2009-03-13 Thread Bulat Ziganshin
Hello Don,

Friday, March 13, 2009, 8:08:57 PM, you wrote:

 What is the reason why you have decided to use unpinned arrays
 (ByteArray#) instead of pinned arrays (Foreign.Ptr)?

 They prevent heap fragmentation (and in general are faster).

you probably mean faster alloc/gc operations, everything else should
be the same


-- 
Best regards,
 Bulatmailto:bulat.zigans...@gmail.com

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


Re: [Haskell-cafe] Vim support for cabal

2009-03-13 Thread andy morris
2009/3/13 Pavel Perikov peri...@gmail.com:
 Hi café !

 I googled for some kind of vim support for  cabal but found nothing. I mean
 syntax highlighting of .cabal and probably integration with haskellmode. Did
 anyone hear about such thing?

 Pavel

I've been wanting something like this as well, so you inspired me to
finally get round to writing it. :D

I've stuck it on Patch-tag, so:
darcs get http://patch-tag.com/publicrepos/cabal-vim

Nothing special at the moment; it just highlights field names and does
some basic autoindenting. If you (or someone else on the list) have
any suggestions, then just say (or send a patch if you want :) )

I might add to it over the weekend as well (highlighting of compiler
names in the 'tested-on' field, that sort of thing), so perhaps check
back in a few days.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] broken IO support in uvector package, when using non primitive types

2009-03-13 Thread Manlio Perillo

Hi.

I'm sure this is a know bug, but I can't find details with Google.

The offending code is here:
http://hpaste.org/fastcgi/hpaste.fcgi/view?id=2362

When I execute the program I get:
  uio: readChunkBU: can't read

What's the problem?


I'm using uvector from:
http://code.haskell.org/~dons/code/uvector/



Thanks   Manlio Perillo

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


Re: [Haskell-cafe] broken IO support in uvector package, when using non primitive types

2009-03-13 Thread Daniel Fischer
Am Freitag, 13. März 2009 21:18 schrieb Manlio Perillo:
 Hi.

 I'm sure this is a know bug, but I can't find details with Google.

 The offending code is here:
 http://hpaste.org/fastcgi/hpaste.fcgi/view?id=2362

 When I execute the program I get:
uio: readChunkBU: can't read

 What's the problem?


 I'm using uvector from:
 http://code.haskell.org/~dons/code/uvector/



 Thanks   Manlio Perillo


Worked with uvector-0.1.0.1:

$ ghc --make readUArr.hs
[1 of 1] Compiling Main ( readUArr.hs, readUArr.o )
Linking readUArr ...
$ ./readUArr
2

But not with uvector-0.2
$ ./readUArr
readUArr: readChunkBU: can't read
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] broken IO support in uvector package, when using non primitive types

2009-03-13 Thread Daniel Peebles
As far as I know, the reason for this is that the UIO instance for
productions writes the two rows out sequentially to file, but
doesn't include any means to determine the length of the two halves
when it's loading up again. When you try to read the production back
in, it tries to read in two arrays, but the first array read consumes
all the input leaving the second with nothing.

Having said that, I'm not sure why it used to work. I remember testing
this on the version in hackage and finding the same issue.

Cheers,
Dan

On Fri, Mar 13, 2009 at 4:46 PM, Daniel Fischer
daniel.is.fisc...@web.de wrote:
 Am Freitag, 13. März 2009 21:18 schrieb Manlio Perillo:
 Hi.

 I'm sure this is a know bug, but I can't find details with Google.

 The offending code is here:
 http://hpaste.org/fastcgi/hpaste.fcgi/view?id=2362

 When I execute the program I get:
    uio: readChunkBU: can't read

 What's the problem?


 I'm using uvector from:
 http://code.haskell.org/~dons/code/uvector/



 Thanks   Manlio Perillo


 Worked with uvector-0.1.0.1:

 $ ghc --make readUArr.hs
 [1 of 1] Compiling Main             ( readUArr.hs, readUArr.o )
 Linking readUArr ...
 $ ./readUArr
 2

 But not with uvector-0.2
 $ ./readUArr
 readUArr: readChunkBU: can't read
 ___
 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] broken IO support in uvector package, when using non primitive types

2009-03-13 Thread Don Stewart
UIO's also only a truly alpha idea as a proxy for bytestring/Binary
support.

Patches welcome.

pumpkingod:
 As far as I know, the reason for this is that the UIO instance for
 productions writes the two rows out sequentially to file, but
 doesn't include any means to determine the length of the two halves
 when it's loading up again. When you try to read the production back
 in, it tries to read in two arrays, but the first array read consumes
 all the input leaving the second with nothing.
 
 Having said that, I'm not sure why it used to work. I remember testing
 this on the version in hackage and finding the same issue.
 
 Cheers,
 Dan
 
 On Fri, Mar 13, 2009 at 4:46 PM, Daniel Fischer
 daniel.is.fisc...@web.de wrote:
  Am Freitag, 13. März 2009 21:18 schrieb Manlio Perillo:
  Hi.
 
  I'm sure this is a know bug, but I can't find details with Google.
 
  The offending code is here:
  http://hpaste.org/fastcgi/hpaste.fcgi/view?id=2362
 
  When I execute the program I get:
     uio: readChunkBU: can't read
 
  What's the problem?
 
 
  I'm using uvector from:
  http://code.haskell.org/~dons/code/uvector/
 
 
 
  Thanks   Manlio Perillo
 
 
  Worked with uvector-0.1.0.1:
 
  $ ghc --make readUArr.hs
  [1 of 1] Compiling Main             ( readUArr.hs, readUArr.o )
  Linking readUArr ...
  $ ./readUArr
  2
 
  But not with uvector-0.2
  $ ./readUArr
  readUArr: readChunkBU: can't read
  ___
  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] Using a monad to decompose a function into functions

2009-03-13 Thread Cristiano Paris
2009/3/13 Marcin Kosiba marcin.kos...@gmail.com:
 Hi,
        I've already checked those out. I tried using your yield 
 implementation and
 while it works, I couldn't get it to work with the state monad.
        So while:
 data RecPair a b = Nil | RP (b, a - RecPair a b)
 yield x = Cont $ \k - RP (x, k)

        got me half-way to my goal, I couldn't figure out how to make 
 something like:

 yield' = do
  state - get
  state' - yield state
  put state'

Basically, the yield is built upon the Cont monad which has a
transformer counter part, ContT. You could try and re-implement the
yield under ContT instead of just Cont then you can stack ContT on top
of State (or StateT if you need more monads) and have a state (i.e.
get/put) and the yield.

Hope this helps.

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


Re: [Haskell-cafe] broken IO support in uvector package, when using non primitive types

2009-03-13 Thread Manlio Perillo

Daniel Peebles ha scritto:

As far as I know, the reason for this is that the UIO instance for
productions writes the two rows out sequentially to file, but
doesn't include any means to determine the length of the two halves
when it's loading up again. When you try to read the production back
in, it tries to read in two arrays, but the first array read consumes
all the input leaving the second with nothing.



Ok, thanks.

For now, I think that the simple solution is to not use UArr (a:*:b), but
(UArr a, UArr b).


Or I should just switch to Data.Array.Unboxed.
The operations I need with the array are only:
- sum of elements
- binary search
- serialization/deserialization
- sorting (but right now I sort the list before creating the array)

with a very big data set.

For my problem, is uvector the best solution?
What about storablevector or cvector, instead?



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


Re: [Haskell-cafe] broken IO support in uvector package, when using non primitive types

2009-03-13 Thread Don Stewart
 As far as I know, the reason for this is that the UIO instance for
 productions writes the two rows out sequentially to file, but
 doesn't include any means to determine the length of the two halves
 when it's loading up again. When you try to read the production back
 in, it tries to read in two arrays, but the first array read consumes
 all the input leaving the second with nothing.


 Ok, thanks.

 For now, I think that the simple solution is to not use UArr (a:*:b), but
 (UArr a, UArr b).
 
Just newtype your own UIO instance, if you need a different instance...

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


Re: [Haskell-cafe] broken IO support in uvector package, when using non primitive types

2009-03-13 Thread Manlio Perillo

Daniel Fischer ha scritto:

[...]
Worked with uvector-0.1.0.1:

 [...]
But not with uvector-0.2

 [...]

The main difference is that in uvector 0.2, hPutBU does not write in the 
file the length of the array; hGetBU simply use the file size.


   let elemSize = sizeBU 1 (undefined :: e)
   n - fmap ((`div`elemSize) . fromInteger) $ hFileSize h


So, the problem seems to be here.
This simply don't support having two arrays written in the same file, 
and sizeBU belongs to the UAE class, whose instances are only declared 
for builtin types.



So, the patch is: just revert this change.


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


Re: [Haskell-cafe] broken IO support in uvector package, when using non primitive types

2009-03-13 Thread Don Stewart
manlio_perillo:
 Daniel Fischer ha scritto:
 [...]
 Worked with uvector-0.1.0.1:

  [...]
 But not with uvector-0.2
  [...]

 The main difference is that in uvector 0.2, hPutBU does not write in the  
 file the length of the array; hGetBU simply use the file size.

let elemSize = sizeBU 1 (undefined :: e)
n - fmap ((`div`elemSize) . fromInteger) $ hFileSize h


 So, the problem seems to be here.
 This simply don't support having two arrays written in the same file,  
 and sizeBU belongs to the UAE class, whose instances are only declared  
 for builtin types.


 So, the patch is: just revert this change.

Or... use your own UIO instance. That's why it's a type class!

Anyway, for the background on this:

Tue Nov 18 08:44:46 PST 2008 Malcolm Wallace
  * Use hFileSize to determine arraysize, rather than encoding it in the
  file.

Here is a patch to the uvector library that fixes hGetBU and hPutBU to
use the filesize to determine arraysize, rather than encoding it within
the file.  I guess the disadvantages are that now only one array can
live in a file, and the given Handle must indeed be a file, not a socket
Handle.  But the advantage is that one can read packed raw datafiles
obtained externally.

Still, again, I'd point out that uvector is alpha, APIs can and will
change. 

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


Re: [Haskell-cafe] broken IO support in uvector package, when using non primitive types

2009-03-13 Thread Manlio Perillo

Don Stewart ha scritto:

[...]


So, the patch is: just revert this change.


Or... use your own UIO instance. That's why it's a type class!



Why should I rewrite the UIO instance, if one already exists?


Anyway, for the background on this:

Tue Nov 18 08:44:46 PST 2008 Malcolm Wallace
  * Use hFileSize to determine arraysize, rather than encoding it in the
  file.

Here is a patch to the uvector library that fixes hGetBU and hPutBU to
use the filesize to determine arraysize, rather than encoding it within
the file.  I guess the disadvantages are that now only one array can
live in a file, and the given Handle must indeed be a file, not a socket
Handle.  But the advantage is that one can read packed raw datafiles
obtained externally.

Still, again, I'd point out that uvector is alpha, APIs can and will
change. 



Ok, with API changes.
But they *should not* break normal package usage.

That patch simply introduced a bug in uvector.
If you think that the patch is useful, then the patch should also 
include a modification to the UIO instance for a:*:b.



Regards  Manlio


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


Re: [Haskell-cafe] broken IO support in uvector package, when using non primitive types

2009-03-13 Thread Daniel Fischer
Am Freitag, 13. März 2009 23:53 schrieb Don Stewart:
 manlio_perillo:
  Daniel Fischer ha scritto:
  [...]
  Worked with uvector-0.1.0.1:
 
   [...]
  But not with uvector-0.2
 
   [...]
 
  The main difference is that in uvector 0.2, hPutBU does not write in the
  file the length of the array; hGetBU simply use the file size.
 
 let elemSize = sizeBU 1 (undefined :: e)
 n - fmap ((`div`elemSize) . fromInteger) $ hFileSize h
 
 
  So, the problem seems to be here.
  This simply don't support having two arrays written in the same file,
  and sizeBU belongs to the UAE class, whose instances are only declared
  for builtin types.
 
 
  So, the patch is: just revert this change.

 Or... use your own UIO instance. That's why it's a type class!

 Anyway, for the background on this:

 Tue Nov 18 08:44:46 PST 2008 Malcolm Wallace
   * Use hFileSize to determine arraysize, rather than encoding it in
 the file.

 Here is a patch to the uvector library that fixes hGetBU and hPutBU to
 use the filesize to determine arraysize, rather than encoding it within
 the file.  I guess the disadvantages are that now only one array can
 live in a file, and the given Handle must indeed be a file, not a
 socket Handle.  But the advantage is that one can read packed raw datafiles
 obtained externally.

 Still, again, I'd point out that uvector is alpha, APIs can and will
 change.

 -- Don

Though I don't really know whether what I did is sane, I can offer a few 
patches which seem to work. 
Check for sanity before applying :)

hunk ./Data/Array/Vector/Prim/BUArr.hs 85
-  hPutBU, hGetBU
+  hPutBU, hGetBU, hGetLengthBU

hunk ./Data/Array/Vector/Prim/BUArr.hs 864
+hGetLengthBU :: forall e. UAE e = Int - Handle - IO (BUArr e)
+hGetLengthBU numEntries h =
+  do
+marr@(MBUArr _ marr#) - stToIO (newMBU numEntries)
+let bytes = sizeBU numEntries (undefined :: e)
+wantReadableHandle hGetBU h $
+\han...@handle__{ haFD=fd, haBuffer=ref, haIsStream=is_stream } - do
+  b...@buffer { bufBuf = raw, bufWPtr = w, bufRPtr = r } - readIORef ref
+  let copied= bytes `min` (w - r)
+  remaining = bytes - copied
+  newr  = r + copied
+  newbuf | newr == w = buf{ bufRPtr = 0, bufWPtr = 0 }
+ | otherwise = buf{ bufRPtr = newr }
+  --memcpy_ba_baoff marr# raw (fromIntegral r) (fromIntegral copied)
+  memcpy_ba_baoff marr# raw (fromIntegral r) (fromIntegral copied)
+  writeIORef ref newbuf
+  readChunkBU fd is_stream marr# copied remaining
+  stToIO (unsafeFreezeAllMBU marr)
+

hunk ./Data/Array/Vector/UArr.hs 59
-  BUArr, MBUArr, UAE,
-  lengthBU, indexBU, sliceBU, hGetBU, hPutBU,
+  BUArr, MBUArr, UAE(..),
+  lengthBU, indexBU, sliceBU, hGetBU, hGetLengthBU, hPutBU,

hunk ./Data/Array/Vector/UArr.hs 867
+  hGetLengthU :: Int - Handle - IO (UArr a)

hunk ./Data/Array/Vector/UArr.hs 875
+primGetLengthU :: UPrim a = Int - Handle - IO (UArr a)
+primGetLengthU n = liftM mkUAPrim . hGetLengthBU n
+

hunk ./Data/Array/Vector/UArr.hs 880
-instance UIO Bool   where hPutU = primPutU; hGetU = primGetU
-instance UIO Char   where hPutU = primPutU; hGetU = primGetU
-instance UIO Intwhere hPutU = primPutU; hGetU = primGetU
-instance UIO Word   where hPutU = primPutU; hGetU = primGetU
-instance UIO Float  where hPutU = primPutU; hGetU = primGetU
-instance UIO Double where hPutU = primPutU; hGetU = primGetU
+instance UIO Bool   where hPutU = primPutU; hGetU = primGetU; hGetLengthU = 
primGetLengthU
+instance UIO Char   where hPutU = primPutU; hGetU = primGetU; hGetLengthU = 
primGetLengthU
+instance UIO Intwhere hPutU = primPutU; hGetU = primGetU; hGetLengthU = 
primGetLengthU
+instance UIO Word   where hPutU = primPutU; hGetU = primGetU; hGetLengthU = 
primGetLengthU
+instance UIO Float  where hPutU = primPutU; hGetU = primGetU; hGetLengthU = 
primGetLengthU
+instance UIO Double where hPutU = primPutU; hGetU = primGetU; hGetLengthU = 
primGetLengthU

hunk ./Data/Array/Vector/UArr.hs 887
-instance UIO Word8  where hPutU = primPutU; hGetU = primGetU
-instance UIO Word16 where hPutU = primPutU; hGetU = primGetU
-instance UIO Word32 where hPutU = primPutU; hGetU = primGetU
-instance UIO Word64 where hPutU = primPutU; hGetU = primGetU
+instance UIO Word8  where hPutU = primPutU; hGetU = primGetU; hGetLengthU = 
primGetLengthU
+instance UIO Word16 where hPutU = primPutU; hGetU = primGetU; hGetLengthU = 
primGetLengthU
+instance UIO Word32 where hPutU = primPutU; hGetU = primGetU; hGetLengthU = 
primGetLengthU
+instance UIO Word64 where hPutU = primPutU; hGetU = primGetU; hGetLengthU = 
primGetLengthU

hunk ./Data/Array/Vector/UArr.hs 892
-instance UIO Int8   where hPutU = primPutU; hGetU = primGetU
-instance UIO Int16  where hPutU = primPutU; hGetU = primGetU
-instance UIO Int32  where hPutU = primPutU; hGetU = primGetU
-instance UIO Int64  where hPutU = primPutU; hGetU = primGetU
+instance UIO Int8   where hPutU = primPutU; hGetU = primGetU; 

Re: [Haskell-cafe] broken IO support in uvector package, when using non primitive types

2009-03-13 Thread Don Stewart
manlio_perillo:
 Don Stewart ha scritto:
 [...]

 So, the patch is: just revert this change.

 Or... use your own UIO instance. That's why it's a type class!


 Why should I rewrite the UIO instance, if one already exists?

Oh, because you want different serialization semantics to the
(arbitrary) defaults.

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


Re: [Haskell-cafe] broken IO support in uvector package, when using non primitive types

2009-03-13 Thread Daniel Peebles
The main issue seems to be that although the semantics of UIO may be
arbitrary, Wallace's patch actually broke deserialization for any
production-based UArr, and I'm not sure the benefits are worthwhile
(loading a file someone else sent you) given that endianness is
already not taken into account when loading (so the chances of someone
giving you a raw binary file that happens to contain values of the
correct endianness is rather low, it seems).

On a related note, having a (more) complete testsuite might help
prevent patches like this from breaking existing functionality.

Maybe a way to resolve the issue is to use the file size and break it
according to the size of the two halves of the production? This avoids
prefixing array length, but allows the productions to still work.

Either way, I'm in the process of writing a Binary instance, so maybe
we can get the best of both worlds eventually.

Thanks,
Dan

On Fri, Mar 13, 2009 at 7:21 PM, Don Stewart d...@galois.com wrote:
 manlio_perillo:
 Don Stewart ha scritto:
 [...]

 So, the patch is: just revert this change.

 Or... use your own UIO instance. That's why it's a type class!


 Why should I rewrite the UIO instance, if one already exists?

 Oh, because you want different serialization semantics to the
 (arbitrary) defaults.

 -- Don
 ___
 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] broken IO support in uvector package, when using non primitive types

2009-03-13 Thread Don Stewart
I'd like to do away with UIO altogether though.

pumpkingod:
 The main issue seems to be that although the semantics of UIO may be
 arbitrary, Wallace's patch actually broke deserialization for any
 production-based UArr, and I'm not sure the benefits are worthwhile
 (loading a file someone else sent you) given that endianness is
 already not taken into account when loading (so the chances of someone
 giving you a raw binary file that happens to contain values of the
 correct endianness is rather low, it seems).
 
 On a related note, having a (more) complete testsuite might help
 prevent patches like this from breaking existing functionality.
 
 Maybe a way to resolve the issue is to use the file size and break it
 according to the size of the two halves of the production? This avoids
 prefixing array length, but allows the productions to still work.
 
 Either way, I'm in the process of writing a Binary instance, so maybe
 we can get the best of both worlds eventually.
 
 Thanks,
 Dan
 
 On Fri, Mar 13, 2009 at 7:21 PM, Don Stewart d...@galois.com wrote:
  manlio_perillo:
  Don Stewart ha scritto:
  [...]
 
  So, the patch is: just revert this change.
 
  Or... use your own UIO instance. That's why it's a type class!
 
 
  Why should I rewrite the UIO instance, if one already exists?
 
  Oh, because you want different serialization semantics to the
  (arbitrary) defaults.
 
  -- Don
  ___
  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] reddit.com/r/haskell_proposals: Relevance to Google Summer of Code?

2009-03-13 Thread fallintothis
NOTE: This message was originally posted to the subreddit in question
(and has been slightly modified), where I was told that I should post
the question on haskell-cafe.  See
http://www.reddit.com/r/haskell_proposals/comments/847by/ask_relevance_to_google_summer_of_code/

I'm currently researching the possibility of applying for the Google
Summer of Code[1] and (by way of dons's post[2]) have found myself
perusing the Haskell Proposals subreddit for project ideas. As an
accepted MS CS student, I've spent my undergraduate life annoying
professors by using a slew of different programming languages -- most
recently, Haskell. While not altogether unfamiliar with the language,
I rather doubt (or at least try to honestly question) how useful a
contributor I'd be to some of the larger projects that have been
posted (e.g., the Immix garbage collector[3] or loop unrolling[4]),
despite some of their acceptances as tickets on the Summer of Code
Trac[5] and my deep interest in compiler  language theory. There are
projects that match other interests of mine and (in my approximation)
my experience level, but they also tend to be smaller. For example,
the reddit-alike[6] or wiki-embedded Haddock[7].

So, background sap-story notwithstanding, I suppose my general
question is: with respect to the aforementioned Summer of Code post,
is this subreddit meant to be a place for appropriate SoC projects? It
doesn't feel quite like it is, but I would be excited to work on some
of those that I indicated. The telltale sign for a project's
worthiness seems to be that a ticket is already opened on the Trac
that spells out the appropriateness, but this is limiting. More
obviously, to test the fitness of a project, should the idea be opened
as a ticket for the cursory review of others? Should someone who wants
to do Summer of Code work be at any particular level of experience
(dive into GHC's backend versus use Haskell to hack on a project)?
Intuitively, 1 summer's worth of work could probably be found in any
corner of code that meshes with any student's expertise and interests
-- even a reddit-alike can actually be a lot of work. But the catch
(for me) is that when familiarity is relatively low, it's hard to come
up with such ideas. I realize that applications are competitive
against other students, so the range of acceptable submissions would
depend more on the other applicants, but I think it's also important
to address haskell.org's ethos with regards to who they're looking
for.

If there's a more appropriate place to post this question (ha!
singular) I'm more than happy to transplant it.

[1] http://code.google.com/soc/
[2] 
http://www.reddit.com/r/programming/comments/7zfog/anybody_done_the_google_summer_of_code_your/c07twkd
[3] 
http://www.reddit.com/r/haskell_proposals/comments/7wjsc/implement_the_immix_garbage_collector_in_ghc/
[4] 
http://www.reddit.com/r/haskell_proposals/comments/7z1uf/implement_loop_unrolling_for_c_level_loops_in_ghc/
[5] http://hackage.haskell.org/trac/summer-of-code/wiki/Soc2009
[6] 
http://www.reddit.com/r/haskell_proposals/comments/7u48x/a_simple_redditlike_happsbased_proposal_voting/
[7] 
http://www.reddit.com/r/haskell_proposals/comments/7qnwq/haddock_with_embedded_wiki_feature_a_la_rwh_so_we/
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Haskell-Wiki Account registration

2009-03-13 Thread Henning Thielemann


On Fri, 13 Mar 2009, Benjamin L.Russell wrote:


Why not ask new users to identify letters in a random bitmapped image
of a string, as is commonly done?


I assume, because those images are
 1) not accessible by blind people
 2) can be decoded by spammers, since they know how the images are 
generated by common software.
 Thus my suggestion was a simple Haskell specific question, which cannot 
be answered by stupid spambots.

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


Re: [Haskell-cafe] bytestring vs. uvector

2009-03-13 Thread Henning Thielemann


On Mon, 9 Mar 2009, Alexander Dunlap wrote:


- uvector, storablevector and vector are all designed for dealing with
arrays. They *can* be used for characters/word8s but are not
specialized for that purpose, do not deal with Unicode at all, and are
probably worse at it. They are better for dealing with things that you
would generally use arrays for.


Since the Storable instance of Char stores 32 bit values, I expect they 
store full Unicode codes and thus StorableVector can be used for Unicode 
strings without loss. They will require more memory than UTF8 strings, but 
whether they are faster or slower will depend on how expensive UTF8 
decoding/encoding is.

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


Re: [Haskell-cafe] Incompatibility of different (monad transformer) libraries

2009-03-13 Thread Henning Thielemann


On Tue, 10 Mar 2009, ariep wrote:


 Problem instance 

In my code, I use some monad transformers. I used to use the mtl package,
but I recently switched to the combination transformers/monads-tf
(mainly for the Applicative instances).

The same code also uses the haskeline library, for line reading.
Haskeline allows to edit the user's history (previously entered lines), but
only through a Control.Monad.State interface, and that happens to be the
Control.Monad.State from mtl. So now, my package also needs to import
mtl.

This combination of package dependencies gives import conflicts: whenever I
import some Control.Monad.{State,Error,Cont,...} module, there is more than
one package providing such a module.


I think 'transformers' exports Control.Monad.Trans.State. This should not 
conflict with MTL. However, MTL's State type is different from 
transformer's one. Is that your problem?



 Solution? 

For now, I resolve the ambiguity by using Package imports, i.e. annotate
the ambiguous imports by the right package name.

Is this the best solution? The ghc manual states, that the package import
extension should not be necessary. I can think of another solution, by
creating a dedicated package, which imports mtl:Control.Monad.* and
re-exports them under another name, but that's even less elegant than
package imports.


Since the 'cabal' tool became better and better, today I use a cabal file 
even for small programs. Cabal automatically calls GHC with the right 
package exposing and hiding options.

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


Re: [Haskell-cafe] Style Guide for Haskell Code

2009-03-13 Thread Henning Thielemann


On Tue, 10 Mar 2009, Manlio Perillo wrote:


After a quick search with Google, it seems that there is not yet an
official document for Style Guide for Haskell Code.

I was only able to found:

http://www.cs.caltech.edu/courses/cs11/material/haskell/misc/haskell_style_guide.html
http://urchin.earth.li/~ian/style/haskell.html
http://github.com/tibbe/haskell-style-guide/tree/master

and, of course, the GHC style guide.


Ah, why does Google not show
  http://haskell.org/haskellwiki/Category:Style ?

Of course, style is a matter of taste. So there are as many good styles as 
programmers and there won't be an official style guide, I'm afraid.

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


Re: [Haskell-cafe] Microsoft PhD Scholarship at Strathclyde

2009-03-13 Thread Henning Thielemann


On Tue, 10 Mar 2009, Conor McBride wrote:


Apologies for crossposting. Please forward this message
to individuals or lists who may be interested. In addition
to the recently advertised PhD position at Strathclyde on
Reusability and Dependent Types, I am delighted to
advertise the following PhD opportunity.

{-
-- Haskell Types with Numeric Constraints 
-}


Sounds like it could simplify
  http://hackage.haskell.org/cgi-bin/hackage-scripts/package/dimensional/
 a lot. However, isn't this halfheartedly since we all wait for full 
dependent types? :-)

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


Re: [Haskell-cafe] A systematic method for deriving a defintion of foldl using foldr?

2009-03-13 Thread Henning Thielemann


On Wed, 11 Mar 2009, R J wrote:


foldl and foldr are defined as follows:

  foldr    :: (a - b - b) - b - [a] - b
  foldr f e [] =  e
  foldr f e (x : xs)   =  f x (foldr f e xs)

  foldl    :: (b - a - b) - b - [a] - b
  foldl f e [] =  e
  foldl f e (x : xs)   =  foldl f (f e x) xs

1.  I understand how these definitions work, and yet I'm unable to implement 
foldl in terms
of foldr.  What's a systematic approach to identifying such an implementation, 
and what is
the implementation?


You are lucky, I recently wrote
  http://haskell.org/haskellwiki/Foldl_as_foldr___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] State monad is missing Applicative instance

2009-03-13 Thread Henning Thielemann


On Thu, 12 Mar 2009, Peter Verswyvelen wrote:


I think. Or is it defined in some other package?


The 'transformers' package has those instances.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Abuse of the monad [was: monadic logo]

2009-03-13 Thread Henning Thielemann


On Thu, 12 Mar 2009, Andrew Wagner wrote:


Can you expand on this a bit? I'm curious why you think this.


http://haskell.org/haskellwiki/Type_classes_are_for_reusability

We recently had a thread about that. I can't find it now.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe