#apache #archlinux #asterisk #centos #debian #gentoo #haskell #kde #kubuntu #lisp #math #mysql #perl #python #ruby-lang #rubyonrails #suse #ubuntu #vim #wikipedia 0 1 2 3 4 5 6 7 8 9
Top Prev 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 Next
#haskell
<Cale> Don't bother!
<Cale> What you really should do is something completely different
<Cale> I'm just explaining why existentials aren't the solution here.
<paolino> ah
<Cale> You create a type which is a union of all the types of values which you could possibly get from the config file.
<paolino> wait
<Cale> and then use the constructors of that type to guide what you do with the values later on.
<paolino> Net/Collectors.hs
<dmhouse> paolino: that means data MyUnion = F Foo | B Bar | Z Baz, where Foo, Bar, Baz are the types you might get from your config file.
<paolino> 3 politcs
<paolino> instances of Collect
<dmhouse> The advantage of using a union is that your constructors essentially become TypeReps. I.e., if you see "F <something>" in the config file, you know <something> :: Foo.
<paolino> user must be able to write
<paolino> KPath (4,8) --or
<paolino> KRPath [2,3,3] --or
<paolino> RandomCollector 5
<paolino> in the config file
<dmhouse> What are the types?
<benja_> data MyUnion = KPath ... | KRPath ... | RandomCollector ...
<Saizan> but even with MyUnion you need rank-2 polymorphism, right?
<dmhouse> Saizan: why?
<Cale> Saizan: nope
<Saizan> ah, you can make MyUnion an instance of Collector?
<Cale> Sure, or whatever is needed :)
<Eighty> is there a way to catch undefined? so the program needn't necessarily end when undefined is reached?
<Cale> Eighty: from the IO monad, and it's a little tricky
<Eighty> tricky how?
<Cale> Eighty: it's a good question to ask yourself whether you could be representing failure explicitly
<Cheery> Are monoids allowed to be self-referencing?
<Cale> Eighty: you have to get the error to happen inside a particular IO call, which means that you have to use Control.Exception.evaluate to sequence the evaluation of the value
<Cheery> like:
<Cale> (specifically, inside of the call to catch)
<Cheery> Funnylist = 1:2:3:Funnylist
<Cale> > let funnylist = 1 : 2 : 3 : funnylist in funnylist
<lambdabot> [1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2...
<Cheery> :) So they are allowed to be.
<Cale> Cheery: absolutely :)
<benja_> Cheery: in general, why not? but with lists, mappend where the lhs is a infinite list will of course loop forever
<Cale> That's not monoids though, that's recursive data types in general.
<Eighty> Cale: okay. how do i catch it then?
<benja_> Cheery: if you have data Tree a = Branch (Tree a) (Tree a) | Leaf a
<Cale> Eighty: What's the type of the thing which might be undefined? Is there a data structure which might have some undefined values in it that you want to catch, or is it just a single thing?
<benja_> or more simply, Tree = Branch Tree Tree | Nil,
<benja_> and instance Monoid Tree where { mempty = Nil, mappend l r = Branch l r }
<benja_> then there is no problem with looping
<Eighty> Cale: i'm using error "you can't do that, sillypants!" in lots of places in pure functions, and when i later compose it into a program, i'd like to be able to catch undefined instead of just having the program exit abruptly
<Cale> catch (evaluate x) (\e -> ...)
<Cale> Eighty: if they're your own calls, you'd probably be better off using Either
<Cale> Either String a
<benja_> ...hmm, of course you would have to process the trees in a way that (a `Branch` b) `Branch` c is equivalent to a `Branch` (b `Branch` c)...
Previous Page Next Page