Re: [Haskell-cafe] Hoogle vs Hayoo

2013-08-23 Thread Daniel Trstenjak

On Fri, Aug 23, 2013 at 10:12:27AM +0200, Erik Hesselink wrote:
> Note that the 'normal' hoogle indexes all (?) of hackage. But by
> default it only searches the haskell platform. You can add a package
> with '+' to search in that package. E.g. "PublicKey +crypto-api".

If the idea behind this, that the haskell platform packages should
be the first place to look at, than this could be also achieved by
sorting the search results.

It's a bit pointless, if I have to know the package, where I want to
search in. 


Greetings,
Daniel

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


Re: [Haskell-cafe] Identity of indiscernibles

2013-08-08 Thread Daniel Trstenjak

Hi Tom,

> See [1] for an explanation of free monads in general.  For IO in particular,
> define a functor
> 
> data IOF a = GetChar (Char -> a) | PutChar Char a | ...
> 
> with constructors for all elementary IO operations.

But how should this work if the user adds an IO operation, e.g by wrapping a C 
function?


Greetings,
Daniel

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


Re: [Haskell-cafe] Generating Haskell Code out of Haskell AST (GHC API)

2013-07-19 Thread Daniel Trstenjak

Hi John,

> Alan - I do NOT want to generate Haskell code. I want only to generate AST
> and compile it.
> The question about generating the code was only to have a "debugging tool"
> - to see if the generated AST is good - I wanted to generate the Haskell
> code only to check if its correct, but normally I would not do it, because
> it makes no sense to generate AST -> code -> AST (by GHC) again etc :)
> Additional - I want to connect to GHC's type-checking also and translate
> the errors to be appropriate to my language syntax - so maybe the pure GHC
> API is the best way to go?

I don't know what kind of language you're writing, but I don't think
that this is the easiest approach.

Just trying to convert a GHC error in something meaningful for your
language sounds like a quite painful undertaking, which will end
in some big heuristic algorithm.

I think, that getting good and meaningful errors for your language you
will need to do it by yourself. The result will be easier to maintain
and extend.

I don't quite understand why you're thinking that GHC is at all the
right tool. Well, I don't know exactly what you're really trying to do,
but have you already looked at LLVM (http://llvm.org/)?


Greetings,
Daniel

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


Re: [Haskell-cafe] HTML framework for web-ui

2013-05-21 Thread Daniel Trstenjak

Hi Adrian,

> What's an exception? I thought Haskell used Maybe.

Haskell also has exceptions:

dan@machine ~> ghci
Prelude> head []
*** Exception: Prelude.head: empty list


I also consider them as quite problematic, especially if they're used in
libraries, but sometimes we're all a bit lazy and the 'error' function
comes in handy ...


Greetings,
Daniel

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


Re: [Haskell-cafe] list comprehension doesn't work

2013-05-14 Thread Daniel Trstenjak

Hi Mateusz,

> I don't think my post was out of order at all and I don't understand
> why it sparked such an... energetic response - that wasn't my intent
> at all.

A friendly response might contain the things you told John, but it could
also be a bit more empathic, otherwise its easy to perceive it as harsh.

A friendly community is the result of considering this.


Greetings,
Daniel

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


Re: [Haskell-cafe] case switch covering all possible constructor but still fails

2013-04-13 Thread Daniel Trstenjak

Hi Nathan,

> DataAlt c | Right tag <- genDataConTag c -> return $ Cond tag

Are you sure, that genDataConTag always returns a 'Right'?
If it returns a 'Left', than the pattern won't match.


Greetings,
Daniel

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


Re: [Haskell-cafe] Prolog-style patterns

2013-04-09 Thread Daniel Trstenjak

Hi Jan,

On Tue, Apr 09, 2013 at 01:32:33PM +0200, Jan Stolarek wrote:
> Thanks for pointing me to earlier discussions on this subject - they are 
> enlightening :) One 
> particular argument "against" seems to be very convincing to me:
> 
> "From a language design point of view, it should be noted that turning
> non-left linear patterns into ones with == guards elevates the class Eq
> to built-in status - but the compiler has no semantic control over it."

Yes, I can see the point, but in the case of Haskell with its ability to
automatically derive the Eq instance, there's some kind of semantic
control, and if an user writes a nonsense Eq instance, than he just
really asks for some hurting ;). 

> Regarding the possibility of making accidental mistakes during refactoring 
> etc. This could be 
> implemented as a language extension, requiring explicit LANGUAGE pragma. So 
> people using it would 
> know they have semantics slightly changed and need to be aware that there is 
> a possibility of 
> making these kind of mistakes.

I'm a bit torn between all these GHC extensions. If your code doesn't
compile, did you really made a mistake or just forgot to include a GHC
extension ...

But I also have the feeling, that the extension perhaps might not be
worth it, because the difference between

foo x x = ...

and

foo x y | x == y = ...

is just IMHO too small.


Greetings,
Daniel

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


Re: [Haskell-cafe] Prolog-style patterns

2013-04-09 Thread Daniel Trstenjak

Hi Roman,

> In fact, lots of Haskell newcomers are surprised that
> 
>   f 10 = 42
> 
> is not the same as
> 
>   n = 10
>   f n = 42

Well, yes, at the beginning I've been also surprised about this.

But allowing this seems to be even more error prone, because now you
could "bind" function arguments to values by just importing a module.


module Foo where
n = 10


module Bar where
import Foo

f n = 42


By constraining this "binding" to only the current module you would just add
an other inconsistency.



Greetings,
Daniel

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


Re: [Haskell-cafe] Prolog-style patterns

2013-04-09 Thread Daniel Trstenjak

Hi Roman,

> One issue with it in Haskell is that it'd lead to inconsistent
> semantics:
> 
>   myEq x x = True
> 
> is not the same as
> 
>   myEq x y =
> case y of
>   x -> True

I don't think that it's inconsistent, because the 'case' defines a new name
scope, like the function does for its arguments.

Otherwise you would also expect a different behavior for:

x = 2

myEq x x = True


Greetings,
Daniel

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


Re: [Haskell-cafe] code-as-config, run-time checks and error locations

2013-04-06 Thread Daniel Trstenjak

Hi Steffen,

most of the time I'm just using these cpp macros:

#define __POS__(__FILE__ ++ ":" ++ show __LINE__)
#define ERROR  error $ __POS__ ++ " -> " ++


Instead of writing 'error "blub"' you would write 'ERROR "blub"'
and additionally get the file name and the line.


There's a bracktracing functionality in the more recent versions of
ghc. I think it has been discussed on this mailing list.


Greetings,
Daniel

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


Re: [Haskell-cafe] Remove redundancy with Template Haskell

2013-03-27 Thread Daniel Trstenjak

Hi Corentin,

On Wed, Mar 27, 2013 at 09:13:41PM +0100, Corentin Dupont wrote:
> I have a function that looks like this:
> call :: SomeFunction -> String -> SomeState
> 
> The string is actually the representation of the function passed in
> parameter. It is stored in the state for documentation.
> So a call looks like that:
> call (\a -> putStrLn a)   "\a -> putStrLn a"
> 
> There is a clear redundancy here, how could I remove it with Template
> Haskell?
> I cannot figure out...

You can even use cpp to get something like:

#define CALL(func) call (func) #func

CALL(\a -> a + 1) => call (\a -> a + 1) "\a -> a + 1"


Greetings,
Daniel

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


Re: [Haskell-cafe] Make a DSL serializable

2013-03-25 Thread Daniel Trstenjak

Hi Michael,

On Sun, Mar 24, 2013 at 05:13:35PM -0500, Michael Better wrote:
> Isn't this similar to the problem Cloud Haskell had to solve to send code
> to another process to run?

As much as I know, the sendable code of 'Cloud Haskell' is limited, you
can't just send any kind of function.

https://github.com/jepst/CloudHaskell#process-management


Greetings,
Daniel

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


Re: [Haskell-cafe] Make a DSL serializable

2013-03-24 Thread Daniel Trstenjak

Hi Corentin,

> I have a DSL like this:
> data Exp where
> OnEvent  :: EventName -> (Int -> Exp) -> Exp
> (...)
> 
> The "OnEvent" element carries a function (the handler to be called when the
> event happens), and that makes my DSL non showable/serializable.
> How could I fix that? This is a real handicap not to be able to serialize
> the state of my whole application because of that :)

You could have a unique id for your handlers, which might be
an Int or a String and have some kind of registration for the
handlers.

data Exp where
OnEvent :: EventName -> HandlerId -> Exp

type HandlerId = String
type Handler   = (Int -> Exp)
type Handlers  = HashMap HandlerId Handler

registerHandler :: Handlers -> (HandlerId, Handler) -> Handlers
getHandler  :: Handlers -> HandlerId -> Maybe Handler

But you have to ensure, that for each application run the same
HandlerId also gets the same Handler.


Less flexible but more secure is an ADT for you Handler.

data Handler = DoThat
 | DoSometingElse

You can than just pattern match on your handler and don't need any kind
of registration.


But you can go further and define your own little Handler DSL.


Greetings,
Daniel

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


Re: [Haskell-cafe] Overloading

2013-03-10 Thread Daniel Trstenjak

Hi Peter,

> -- smart constructor with serialNumber
> date serialNumber
>  | serialNumber > 0 = Date serialNumber
>  | otherwise = error ("invalid serialNumber " ++ show serialNumber)

Instead of raising an error it's more secure to return a Maybe value.

date :: Int -> Maybe Date
date serialNumber
   | serialNumber > 0 = Just $ Date serialNumber
   | otherwise= Nothing

> -- smart constructor with day month year
> date2 day month year
> | month >= 1 && month <=12 = undefined
> | otherwise = error ("invalid month " ++ show month)

To increase type safety it's a good idea to use as much explicit data
types instead of Int values as possible:

data Month = January | ...

> If this is the case, what would be the natural Haskell way of
> organizing the smart constructors ? Just number them as above ? Or
> naming them
> dateFromSerialNumber, dateFromDayMonthYear ?

I would use the descriptive names but leave out the 'date', because you could 
still have:

import qualified Date

Date.fromSerialNumber



Greetings,
Daniel

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


Re: [Haskell-cafe] RFC: rewrite-with-location proposal

2013-02-26 Thread Daniel Trstenjak

Hi Michael,

On Mon, Feb 25, 2013 at 02:41:19PM +0200, Michael Snoyman wrote:
> At that point, we've now made two changes to REWRITE rules:
> 
> 1. They can takes a new ALWAYS parameters.
> 2. There's a new, special identifier currentLocation available.
> 
> What would be the advantage is of that approach versus introducing a single
> new REWRITE_WITH_LOCATION pragma?

The name REWRITE_WITH_LOCATION could indicate that it's just a
REWRITE with an additional location, but not that it's used by
the compiler in a different way.

Perhaps using just another word instead of REWRITE could indicate
the difference of application.


Greetings,
Daniel

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


Re: [Haskell-cafe] layers: A prototypical 2d platform game

2013-02-19 Thread Daniel Trstenjak

On Tue, Feb 19, 2013 at 02:15:33PM +0100, Vo Minh Thu wrote:
> Screenshots obviously ;)

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


Re: [Haskell-cafe] layers: A prototypical 2d platform game

2013-02-19 Thread Daniel Trstenjak

Hi Henk-Jan,

> It seems to me that there is something missing from this e-mail.

What are you missing?


Greetings,
Daniel

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


[Haskell-cafe] layers: A prototypical 2d platform game

2013-02-18 Thread Daniel Trstenjak

Hi all,

also if there's not that much to see and only a few minutes of gameplay,
but after spending quite a few hours writing it, getting a feeling for
Haskell and it's usage, perhaps it's in some way useful for someone,
even if just for a few minutes of distraction.

https://github.com/dan-t/layers


Greetings,
Daniel

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


Re: [Haskell-cafe] ANN: hgdbmi 0.2, GDB Machine Interface

2013-01-19 Thread Daniel Trstenjak

Hi Alex,

On Fri, Jan 18, 2013 at 08:26:10PM +0100, Alexander Bernauer wrote:
> I thought it would make sense to use these names for ease of
> reference. Given this, would you still prefer them being grouped in
> separate modules?

Yes, I still think that having separate modules can be beneficial,
also for the ease of reference.

> Gdbmi.Commands is not the only module that depends on the GDB version.

I thought of putting all of your modules under the version indicating
module.

> GDB/MI is in general still evolving and GDB's compliance with the
> documentation keeps on changing on all levels. So I would have to
> maintain all hgdbmi modules for each GDB version. Do you think this
> makes sense and is worth the effort?

At the current level of development, the version indicating module might
be unnecessary and overhead, but you also don't have to support multiple
GDB versions. It's just a more explicit way of telling your user for
which GDB version the binding should work.

You can reuse most of your code for several GDB versions.

Supposed you've implemented the GDB 7.4 bindings and now would like
to support a new command in GDB 7.5 and all other commands behave
still in the same way as in version 7.4.


module Gdbmi.V7_5.Commands (module Gdbmi.V7_4.Commands, newCommand) where

newCommand = ...



Greetings,
Daniel

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


Re: [Haskell-cafe] ANN: hgdbmi 0.2, GDB Machine Interface

2013-01-18 Thread Daniel Trstenjak

Hi Alexander,

On Thu, Jan 17, 2013 at 10:17:33PM +0100, Alexander Bernauer wrote:
> I am happy to announce the second release of hgdbmi, a Haskell
> implementation of the GDB Machine Interface.

Nice project! :)

> PS: This is my first serious Haskell package. If you see something
> that you consider odd, I might have done this simply because I didn't
> know better. I would appreciate if you would let me know in such a
> case.

Looking at the function names: have you got a c programming background?

Instead of using these prefixes you could put the functions into separate
modules.

If the interface depends on the GDB version, than it could make sense to
encode the GDB version into the module name, something like:
Gdbmi.V7_4.Commands


Greetings,
Daniel

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


Re: [Haskell-cafe] Layer on a layer of record syntax in the type synonym?

2012-12-21 Thread Daniel Trstenjak

Hi Christopher,

On Fri, Dec 21, 2012 at 04:36:04AM -0900, Christopher Howard wrote:
> Using a simple type I gave earlier from my monadic type question...
> 
> code:
> 
> data Socket3 a b c = Socket3 a b c
>   deriving (Show)
> 
> 
> Is it possible somehow to layer on record syntax onto a synonym of the type?
> 
> The idea would be something like this...
> 
> code:
> 
> type SpaceShip =
>   Socket3 { engine :: Last Engine
>   , hull :: Last Hull
>   , guns :: [Guns]
>   }
> 
> 
> ...purely for the convenience. But this doesn't seem to work with "type"
> as it assumes you are referring to already made constructors, and
> evidently "newtype" only allows use of a single record. I could wrap it
> in a normal "data" declaration but that would add an extra layer of
> complexity I think.

I don't know in which context you would like to use the SpaceShip type,
but the solution using the very generic Socket3 might bite you later,
because you don't have a concrete type for your SpaceShip and can't 
identify it.

Why having a Socket3 in the first place, what's the point of it?



> 
> -- 
> frigidcode.com
> 



> ___
> 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] Hackage suggestion: Gather the list of the licenses of all dependencies of a package

2012-12-13 Thread Daniel Trstenjak

On Thu, Dec 13, 2012 at 08:40:09PM +0200, Michael Snoyman wrote:
> If you have a commercial use for cpphs, and feel the terms of the (L)GPL
> are too onerous, you have the option of distributing unmodified binaries
> (only, not sources) under the terms of a different licence (see
> LICENCE-commercial).

I think that depedencies to binaries, like cpphs, should be treated
differently than depedencies to libraries, because using a (L)GPL-ed
binary mostly hasn't any implications for a "commercial" user and
also for the output of a (L)GPL-ed binary usually the (L)GPL doesn't apply.

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


[Haskell-cafe] Common function names for '(.) . (.)', '(.) . (.) . (.)' ...?

2012-11-21 Thread Daniel Trstenjak

Greetings,
Daniel

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


Re: [Haskell-cafe] Not exporting a class

2012-11-11 Thread Daniel Trstenjak

Hi Joachim,

On Sun, Nov 11, 2012 at 02:10:34PM +0100, Joachim Breitner wrote:
> dear package authors. If you define a useful class, please think twice
> before you do not export the methods, otherwise something like this will
> happen:

I like the way 'Common Lisp' deals with this issue. Exported symbols can
be accessed by 'package:symbol' and non exported symbols can be accessed
by 'package::symbol'.

By using '::' you could still get something done but know, that you did
something improper and should consult the appropriate maintainer.

You almost have the best of both worlds, because I think that it's a
good thing to export as few symbols as possible.



Greetings,
Daniel

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


[Haskell-cafe] Input Handling, Callbacks, State Machines

2012-11-03 Thread Daniel Trstenjak

Hi all,

I'm currently struggling in the search for a nice abstraction for the
input handling of a game (it's a simple platformer with rectangular platforms).

One good example is the level editor of the game. When pressing the left
mouse button the creation of a new platform is started. As long as the
mouse button is hold the platform can be resized by moving the mouse.
When releasing the mouse button the platform is created with the current shape.

The GUI library I'm using is GLFW. There're several callbacks for key,
mouse button and mouse move events.

Firstly I would like to be able to describe application states, like
the creation of a platform or the definition of the movement of a
platform. The state might add something to the current level rendering
and it changes temporary the callbacks. 

So in the case of a platform creation, the mouse move callback would just
resize the platform, the mouse button callback awaits the button release
and the key callback might only allow the quitting of the current creation.

Above the application states it would be nice to be able to describe the
transition from one state to another.

Perhaps FRP might be a solution for this. But I'm still shying away of
it, because a game might have some hairy state changes and I still don't
see, how FRP makes life in this regard that much easier.


Any Ideas?


Greetings,
Daniel

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


Re: [Haskell-cafe] Sparse records/ADTs

2012-10-24 Thread Daniel Trstenjak

Hi Jon

On Wed, Oct 24, 2012 at 11:08:29AM +0100, Jon Fairbairn wrote:
> for each field, which is tedious (and O(n)). Obviously Templates
> would help, but is there an alternative I’ve missed?

perhaps something like:

data Type = Ta | Tb | Tc ...

data E= Ea A | Eb B | Ec C | ...

type D= HashMap Type E

get :: Type -> D -> Maybe E
get = lookup


Greetings,
Daniel

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


Re: [Haskell-cafe] Platform Versioning Policy: upper bounds are not our friends

2012-08-17 Thread Daniel Trstenjak

On Thu, Aug 16, 2012 at 11:33:17PM -0400, wren ng thornton wrote:
> However, there are certainly cases where we have hard upper
> bounds[1][2][3], and ignoring those is not fine. Circumventing hard
> upper bounds should require altering the .cabal file, given as
> getting things to compile will require altering the source code as
> well.

It's ok to have soft and hard upper bounds, but it should be always
possible to ignore both - having a separate ignore option for each -
without modifying the cabal file.

I've the confidence, that most cabal users should be able to handle
this. Nothing is more annoying if you know what you're doing, but don't
have the power to do it.


Greetings,
Daniel

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


Re: [Haskell-cafe] Platform Versioning Policy: upper bounds are not our friends

2012-08-16 Thread Daniel Trstenjak

On Wed, Aug 15, 2012 at 03:54:04PM -0700, Michael Sloan wrote:
> Upper bounds are a bit of a catch-22 when it comes to library authors evolving
> their APIs:
> 
> 1) If library clients aren't encouraged to specify which version of the
>exported API they target, then changing APIs can lead to opaque compile
>errors (without any information about which API is intended).  This could
>lead the client to need to search for the appropriate version of the
>library.

Having the version number A.B.*, than most packages seem to mostly
increase B or lower parts of the version number.

If an upper bound is missing, than cabal could use any package in the range 
A.*.* .

If an author wants to make breaking changes to his API, than he could
indicate this by increasing A.

I've nothing against your proposal, I just don't think that it will be
done that soon.


Greetings,
Daniel

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


Re: [Haskell-cafe] Data structure containing elements which are instances of the same type class

2012-08-12 Thread Daniel Trstenjak

Hi Oleg,

On Sat, Aug 11, 2012 at 08:14:47AM -, o...@okmij.org wrote:
> I'd like to point out that the only operation we can do on the first
> argument of MkFoo is to show to it. This is all we can ever do:
> we have no idea of its type but we know we can show it and get a
> String. Why not to apply show to start with (it won't be evaluated
> until required anyway)?

It's only a test case. The real thing is for a game and will be
something like:

class EntityT e where
   update  :: e -> e

   render  :: e -> IO ()

   handleEvent :: e -> Event -> e

   getBound:: e -> Maybe Bound


data Entity = forall e. (EntityT e) => Entity e

data Level = Level {
   entities = [Entity],
   ...
   }


Greetings,
Daniel

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


Re: [Haskell-cafe] Data structure containing elements which are instances of the same type class

2012-08-07 Thread Daniel Trstenjak

Hi Joey,

On Tue, Aug 07, 2012 at 02:13:09PM -0400, Joey Adams wrote:
> Are you looking for existential quantification [1]?
> 
> data SomeFoo = forall a. Foo a => a
> 
>  [1]: 
> http://www.haskell.org/ghc/docs/latest/html/users_guide/data-type-extensions.html#existential-quantification

Thanks! Yes, that looks really nice. :)

data A = A deriving Show
data B = B deriving Show
data C = C deriving Show

data Foo = forall a. Show a => MkFoo a (Int -> Bool)

instance Show Foo where
   show (MkFoo a f) = show a

hasId foos id = filter (\(MkFoo a f) -> f id) foos

*Main> let foos = [MkFoo A (==1), MkFoo B (==2), MkFoo C (==3)]
*Main> hasId foos 1
[A]


Greetings,
Daniel

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


[Haskell-cafe] Data structure containing elements which are instances of the same type class

2012-08-07 Thread Daniel Trstenjak

Hi all,

it should be possible a call a function on all elements of the data
structure, to add and remove elements.

What I currently have:

the type class:

class Foo a where
   hasId :: a -> Int -> Maybe a


a few instances:

data A = A deriving Show
instance Foo A where
   hasId a 1 = Just a
   hasId _ _ = Nothing

data B = B deriving Show
instance Foo B where
   hasId a 2 = Just a
   hasId _ _ = Nothing

data C = C deriving Show
instance Foo C where
   hasId a 3 = Just a
   hasId _ _ = Nothing


the data structure holding any instance of Foo, which itself is a
instance of Foo:

data Foos l r = Foos l r
  | FooL l
  | FooR r
  | NoFoos deriving Show

instance (Foo l, Foo r) => Foo (Foos l r) where
   hasId (Foos l r) id =
  case (hasId l id, hasId r id) of
   (Just l, Just r) -> Just $ Foos l r
   (Just l, _ ) -> Just $ FooL l
   (_ , Just r) -> Just $ FooR r
   _-> Nothing


combinator for Foos:

(+++) :: l -> r -> Foos l r
l +++ r = Foos l r
infixr 5 +++


Now I can write:

*Main> A +++ B +++ C +++ A
Foos A (Foos B (Foos C A))
*Main> (A +++ B +++ C +++ A) `hasId` 1
Just (Foos A (FooR (FooR A)))


Doesn't seem that nice. For every operation I would have to extend the
type class. After some operations the data structure contains many
dummy nodes (FooR, FooL).

Is there some nicer way?


Greetings,
Daniel

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


Re: [Haskell-cafe] Maintainer of pngload listening?

2012-06-30 Thread Daniel Trstenjak
Hi Ivan,

thanks, but l have been able to  build it  by myself.

I just want to get the package updated and if the maintainer can't be
reached, than ask for maintainership.

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


[Haskell-cafe] Maintainer of pngload listening?

2012-06-28 Thread Daniel Trstenjak

Hi,

Marko Lauronens email address from the package is invalid, so I'm trying
to reach him this way.

pngload doesn't compile with ghc >= 7.2 because of it's dependency to base and 
haskell98.


Greetings,
Daniel

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