Re: [Haskell-cafe] type level strings?

2011-11-24 Thread oleg
Evan Laforge has defined > data Thing { > thing_id :: ThingId > , thing_stuff :: Stuff > } > newtype ThingId = ThingId String and wishes to statically preclude binary operations with things that have different ThingIds. However, Things and their Ids can be loaded from files and so cannot be

[Haskell-cafe] PEPM12: Second Call For Participation

2011-12-18 Thread oleg
ACM SIGPLAN 2012 Workshop on Partial Evaluation and Program Manipulation http://www.program-transformation.org/PEPM12 January 23-24, 2012. Philadelphia, PA, USA (co-located with POPL'12) Second Call For Participation Program is now available http://www.program-transformation.or

[Haskell-cafe] ST monad

2006-01-03 Thread oleg
Bulat Ziganshin wrote: the following code can't go through typechecking > import Control.Monad.ST > import Data.Array.ST > main = print $ runST $ >do arr <- newArray (1,10) 127 > a <- readArray arr 1 > writeArray arr 1 216 > b <- readArray arr

[Haskell-cafe] Haskell DB bindings

2006-01-10 Thread oleg
a list, we are not given the pointer to the ``current list''. We are merely given the current element of the list. Perhaps the following links might be of help: http://www.eros-os.org/pipermail/e-lang/2004-March/009643.html http://pobox.com/~oleg/ftp/Haskell/misc.html#fold-stre

[Haskell-cafe] Haskell DB bindings

2006-01-11 Thread oleg
Krasimir Angelov wrote: > There are three active database libraries: HDBC, HSQL and Takusen. > It is quite disappointing from my point of view. Recently there was > the same situation with the GUI libraires. I think the dichotomy between lower-level Haskell libraries (whose API is closer/faithfu

[Haskell-cafe] Type Eigenvariable [was: Simple IO Regions]

2006-01-19 Thread oleg
A good explanation is in Section `1. Eigenvariables and generic reasoning' of @inproceedings{MillerTiu, author= {Dale Miller and Alwen Fernanto Tiu}, title = {A Proof Theory for Generic Judgments: An extended abstract}, booktitle = {LICS}, year = {2003}, page

[Haskell-cafe] Re: Type Eigenvariable

2006-01-19 Thread oleg
Bill Wood wrote: > is |nabla x, nabla y. phi(x,y)| logically equivalent to > |forall x, forall y. x <> y only-if phi(x,y)|? I use |P only-if Q| for > |P materially implies Q| First of all, I should remark that Miller and Tiu introduce two calculi (with names that are hardly speakable, even in Te

[Haskell-cafe] Re: Fast Mutable Variables for the IO and ST monads

2006-02-07 Thread oleg
Simon Marlow wrote: > I suggest you follow the same scheme as the unboxed array types, and > have IOURef/STURef types, parameterised over the element type. Of > course, we should have instances for all of the primitive numeric types > plus Ptr, ForeignPtr, StablePtr, Bool. Perhaps it may be wort

[Haskell-cafe] (Un)termination of overloading resolution

2006-02-21 Thread oleg
Martin Sulzmann wrote: > - The type functions are obviously terminating, e.g. > type T [a] = [[a]] clearly terminates. > - It's the devious interaction between instances/superclasss > and type function which causes the type class program > not to terminate. > > Is there a possible fix? Here

[Haskell-cafe] (Un)termination of overloading resolution

2006-02-21 Thread oleg
> Let's consider the general case (which I didn't describe in my earlier > email). > > In case we have an n-ary type function T (or (n+1)-ary type class > constraint T) the conditions says for each > > type T t1 ... tn = t > > (or rule T t1 ... tn x ==> t) > > then rank(ti) > rank(t) for each i=1,

[Haskell-cafe] (Un)termination of overloading resolution

2006-02-21 Thread oleg
Martin Sulzmann wrote: > Let's consider the general case (which I didn't describe in my earlier > email). > In case we have an n-ary type function T (or (n+1)-ary type class > constraint T) the conditions says for each > > type T t1 ... tn = t > > (or rule T t1 ... tn x ==> t) > > then rank(ti) >

[Haskell-cafe] Deepest functor [was: fmap for lists of lists of lists of ...]

2006-03-14 Thread oleg
Greg Buchholz wrote: > Is it possible to make a typeclass like Functor, that has a function > (say "f_map"), which would work for the infinite hierarchy of types: > ([],[[]],[[[]]],...)? You do understand that this requires overlapping instances? Because the type [[Bool]] is still a list. In

[Haskell-cafe] Defining instance needs allow-undecidable-instance?

2006-03-28 Thread oleg
Daniel McAllansmith wrote: > When I try to add MonadError into the types I eventually hit the > requirement for allow-undecidable-instances. Is there some way I can > I avoid having to use this extension? > > class (Num i, Bounded i, Monad m, MonadError String m) > => MonadSource i m | m

[Haskell-cafe] Re: Fundeps: I feel dumb

2006-04-12 Thread oleg
Creighton Hogg wrote: > No instance for (MatrixProduct a (Vec b) c) > arising from use of `<*>' at :1:3-5 > Probable fix: add an instance declaration for (MatrixProduct a > (Vec b) c) > In the definition of `it': it = 10 <*> (vector 10 ([0 .. 9])) Let us look at the instanc

[Haskell-cafe] Re: coherence when overlapping?

2006-04-12 Thread oleg
> But I am still confused by the exact definition of coherence in the case of > overlapping. Does the standard coherence theorem apply? If yes, how? > If no, is there a theorem? Yes, the is, by Martin Sulzmann et al, the Theory of overloading (the journal version) http://www.comp.nus.edu.

[Haskell-cafe] Re: coherence when overlapping?

2006-04-13 Thread oleg
It seems that the subject is a bit more complex, and one can force GHC to choose the less specific instance (if one confuses GHC well enough): see the example below. First of all, the inequality constraint is already achievable in Haskell now: "TypeEq t1 t2 False" is such a constraint. One can wr

[Haskell-cafe] Local Fundeps [was: Fundeps: I feel dumb]

2006-04-13 Thread oleg
Creighton Hogg posed the following problem. Given a rather straightforward matrix multiplication code > -- The elements and the size > data Vec a = Vec (Array Int a) Int deriving (Show,Eq) > type Matrix a = (Vec (Vec a)) > class MatrixProduct a b c | a b -> c where > (<*>) :: a -> b -> c > in

[Haskell-cafe] Control.Exceptions and MonadIO

2006-04-21 Thread oleg
Robert Dockins wrote: > One additional (very unfortunate) point is that higher-order IO monad > combinators will not work on your monad, eg, the ones in > Control.Exception. Although that is true in general, for many useful and interesting cases (including ReaderT, the state transformer, and the

[Haskell-cafe] Controlling scope using monadic classes

2006-05-17 Thread oleg
error ``no instance (LabelOK ScopeC ScopeB)'' -- which seems clear. The more elaborate version of similar example can be found here: http://pobox.com/~oleg/ftp/Haskell/types.html#monadic-regions Using labels to enforce well-formedness term constraints (content model constrain

[Haskell-cafe] Re: help with MPTC for type proofs?

2006-05-26 Thread oleg
David Roundy wrote: > class Commutable a b d c > > commute :: Commutable a b d c => > (Patch a b, Patch b c) -> (Patch a d, Patch d c) > > But for this to work properly, I'd need to guarantee that > > 1. if (Commutable a b d c) then (Commutable a d b c) > > 2. for a given three types (a

[Haskell-cafe] On GADT, phantom types, etc. terminology

2006-05-29 Thread oleg
David Roundy wrote: > data CommuteResult a b c where > CR :: C a b c d => (P a d, P d c) -> CommuteResult a b c > ... > or that somehow GADTs aren't interacting with FDs as I'd like It must be emphasized that there are *NO* GADTs is the above code. Except Stefan Monnier's message, no code pos

[Haskell-cafe] Re: Inferring types from functional dependencies

2006-06-10 Thread oleg
Jeff Harper defined typeclasses > class Reciprocate a b | a -> b where > recip :: a -> b > class Multiply a b c | a b -> c where > (*) :: a -> b -> c and encountered the problem with > -- Here I define a default (/) operator that uses the > -- Reciprocate and Multiply class to perform

[Haskell-cafe] Functional programming for processing of large raster images

2006-06-20 Thread oleg
Recently Vo Minh Thu wondered if Haskell (or, I generalize, functional programming) can be of much use for computer graphics programming. I'd like to point out a project that experimentally shown that functional programming is of great help for processing of large raster images (24-bit PPM files)

[Haskell-cafe] Re: Functional _meta_programming for processing of large raster images

2006-06-21 Thread oleg
I'm afraid the _meta_ programming aspect of the image processing project may be overlooked. Joel Reymont wrote: > I think the issue wasn't using functional programming for large image > processing, it was using Haskell. OCaml is notoriously fast and > strict. Haskell/GHC is... lazy. Well, i

[Haskell-cafe] Re: technique to allow innocuous ambiguity in instance declarations?

2006-07-11 Thread oleg
. And then we examine f and g to see what we've got and how to proceed from that. At that point, it's us who decides what to improve first. The idea is similar to the one described in http://pobox.com/~oleg/ftp/Haskell/types.html#is-function-type The complete code follows. Now test

[Haskell-cafe] Type level logic programming terminology

2006-07-20 Thread oleg
Most systems of (first-order) logic differentiate between function letters (aka, symbols) and predicate letters (symbols). The former are used to build terms; the latter build atomic formulas (which can later be combined in more complex formulas using negation, conjunction, disjunction, and quanti

[Haskell-cafe] Re: Type hackery help needed!

2006-08-05 Thread oleg
y are explained in http://pobox.com/~oleg/ftp/Haskell/typecast.html Incidentally, that web page's source also gives an illustration of their use: http://pobox.com/~oleg/ftp/Haskell/typecast.hs The page itself is written in HSXML, which had to deal with a similar problem

[Haskell-cafe] Local functional dependencies: solving show . read and XML generation problems

2006-08-14 Thread oleg
Sorry for a late reply, I'm out of town. As I understand it, the problem is as follows: we'd like to construct different realizations of XML documents from data of different types. We wish to write p (p "foo") and specify the desired type of the XML document, like (p (p "foo")) :: X

[Haskell-cafe] head as a total function

2006-09-06 Thread oleg
packed strings, general recursion and creative index expressions) can be handled. Again, without introducing any runtime overhead: http://pobox.com/~oleg/ftp/Haskell/KMP-deptype.hs The approach is formalizable; the recent PLPV talk by Chung-chieh Shan presented the types systems and the pr

[Haskell-cafe] Re: variadic functions and typeCast

2006-09-27 Thread oleg
of TypeCast that works within the same module, please see any code described in http://pobox.com/~oleg/ftp/Haskell/typecast.html Appendix D of the full HList paper (or, HList technical report, I should say) gives the reasons for TypeCast. Briefly, TypeCast lets us replace a (ground) type T

[Haskell-cafe] Typeclass vs. Prolog programming

2006-09-27 Thread oleg
This message is intended as a long answer to Michael Shulman's question (Re: variadic functions and typeCast) and Jason Dagit's question (Re: Duplicate Instance problem). Incidentally, the short answer to Jason Dagit's question is `constraints are disregarded during instance selection'. The answer

[Haskell-cafe] Re: Duplicate Instance problem

2006-09-28 Thread oleg
Jason Dagit wrote: > I tried to create a type class for making instances of Show display a > custom way. After using my class for a while I found that sometimes > RealFloats would display as 'NaN' and this is unacceptable. So at > this point I had something like: > > class Show a => StringValue

[Haskell-cafe] Re: Typeclass vs. Prolog programming

2006-09-30 Thread oleg
I previously wrote: > The typechecker commits to the instance > and adds to the current constraints > TypeCast x Int, Ord Bool, Eq Bool > The latter two are obviously satisfied and so discharged. The former > leads to the substitution {x->Int}. I should have been more precise and said:

[Haskell-cafe] irrefutable patterns for existential types / GADTs

2006-09-30 Thread oleg
It seems that irrefutable pattern match with existentials is safe. The fact that irrefutable pattern match with GADT is unsafe has been demonstrated back in September 2004. Let us consider the following regular existential data type > data TFoo where >Foo :: Show a => a -> TFoo >Bar :: I

[Haskell-cafe] Problematic irrefutable pattern matching of existentials

2006-10-01 Thread oleg
I have come to realize that irrefutable pattern matching of existentials may indeed be problematic. Let us consider the following existential data type > data FE = forall a. Typeable a => Foo a > | forall a. Typeable a => Bar a The following tests type and run (the latter raising the exp

[Haskell-cafe] Re: OOHaskell problems

2006-10-03 Thread oleg
> I wanted to try using OOHaskell as a library, but I've run into some > problems I don't understand. > I downloaded the copy from: > http://homepages.cwi.nl/~ralf/OOHaskell/ both HList and OOHaskell are now available via DARCS http://darcs.haskell.org/HList/ http://darcs.haskell.

[Haskell-cafe] Trying to understand HList / hMapOut

2006-10-07 Thread oleg
> I am using a heterogenous list as in [1] all elements of which are of > a given class C. > Since foo maps all class members to Int, hMapOut should be a > straight-forward way to produce homogenous Int lists from heterogenous > CLists: > > test :: (CList l) => l -> [Int] > test = hMapOut foo Wel

[Haskell-cafe] Re: Trying to understand HList / hSequence now [why it works]

2006-10-10 Thread oleg
Matthias Fischmann wrote: > instance (Monad m, HSequence m HNil HNil) => HSequence m HNil HNil > where hSequence _ = return HNil > > how can i use the goal of the declaration as one of the conditions > without causing some sort of black hole in the type inference > algorithm? Very easily: th

[Haskell-cafe] Re: type level functions (type of decreasing list)

2006-10-17 Thread oleg
constrained to be in the decreasing, increasing, or any other (defined in the future) order. This example shows that Haskell truly has more kinds than it is commonly acknowledged. For more details on constrained lists (list of odd numerals, even numerals, etc), please see the following implementat

[Haskell-cafe] Re: 6.4 -> 6.6, scoped type variables

2006-10-18 Thread oleg
I too miss the old way of handling local type variables. Previously, local type annotations worked a lot like an additional constraint, with type variables denoting some type. The same type variable denoted the same type. Here's how it works in OCaml, for example: # let pair x y = (x,y);; val pai

[Haskell-cafe] Re: Strictness, order of IO operations: NewCGI & HDBC

2006-10-20 Thread oleg
Tim Smith wrote: > Has anyone found out how to lift bracket into another monad? Yes, please see the thread `Re: Control.Exceptions and MonadIO' staring at http://www.haskell.org/pipermail/haskell-cafe/2006-April/015444.html There is also a Haskell' ticket: http://hackage.haskell.org/t

[Haskell-cafe] Re: function types as instances of Num

2006-10-29 Thread oleg
The problem seems equivalent to the following: http://pobox.com/~oleg/ftp/Haskell/typecast.html#local-fd That is, the inferred type is too general to chose the appropriate instance. The solution is also the same: either add type annotations to restrict the inferred type (and so make it

[Haskell-cafe] An example of dependent types [was: Simple GADT parser for the eval example]

2006-11-01 Thread oleg
Greg Buchholz has posed an interesting problem of writing a typechecker. Given untyped terms of the form > data Expr = ELit Int > | EInc Expr > | EIsZ Expr we are to compute typed terms: > data Term a where > Lit :: Int -> Term Int > Inc :: Term In

[Haskell-cafe] Re: Debugging partial functions by the rules

2006-11-15 Thread oleg
Donald Bruce Stewart wrote: > So all this talk of locating head [] and fromJust failures got me > thinking: > > Couldn't we just use rewrite rules to rewrite *transparently* > all uses of fromJust to safeFromJust, tagging the call site > with a location? I'm sorry for shifting the top

Re: [Haskell-cafe] Re: Debugging partial functions by the rules

2006-11-15 Thread oleg
loop l accum = indeedFL l accum $ >(\l -> loop (tail l) (head l : accum)) > > test1 = safe_reverse [1,2,3] As we can see, the null test is algorithmic. After we've done it, head and tail no longer need to check for null list. Those head and tail functi

Re: [Haskell-cafe] Re: Debugging partial functions by the rules

2006-11-15 Thread oleg
Jan-Willem Maessen wrote: > In addition, we have this rather nice assembly of functions which > work on ordinary lists. Sadly, rewriting them all to also work on > NonEmptyList or MySpecialInvariantList is a nontrivial task. That's an excellent question. Indeed, let us assume we have a func

[Haskell-cafe] Partial signatures

2004-08-06 Thread oleg
Malcolm Wallace wrote: > and since you cannot write a partial signature, Can't we really? It seems `partial signature' means one of two things: - we wish to add an extra constraint to the type of the function but we don't wish to explicitly write the type of the func

RE: [Haskell-cafe] closed classes [was: Re: exceptions vs. Either]

2004-08-09 Thread oleg
Simon Peyton-Jones wrote: > kind HNat = HZero | HSucc HNat > > class HNatC (a::HNat) > > instance HNatC HZero > instance HNatC n => HNatC (HSucc n) > > There is no way to construct a value of type HZero, or (HSucc HZero); > these are simply phantom types. ... A mer

[Haskell-cafe] Layered I/O

2004-09-15 Thread oleg
context of Scheme, is available here: http://pobox.com/~oleg/ftp/Scheme/io.txt More polished drafts exist, and even a prototype implementation. Unfortunately, once it became clear that the ideas are working out, the motivation fizzled. The discussion of i18n i/o highlighted the need for general

Re: [Haskell-cafe] existential type problem

2004-10-15 Thread oleg
Andrew Pimlott wrote: > I want values in my existential type to denote, for some monad, a > monadic operation and a way to run the monad. Except, I want it mix > the operation with operations in another monad, so it use a monad > transformer. I'm afraid, that phrase was a little misleading. It s

[Haskell-cafe] Re: How do I get a long iteration to run in constant space

2004-10-05 Thread oleg
I added two lines to your code: iterate2 f x n | seq f $ seq x $ seq n $ False = undefined iterate2 f x n = --- as before rk4Next f h (x, y) | seq f $ seq h $ seq x $ seq y $ False = undefined rk4Next f h (x, y) = -- as before I also increased ten times the number of steps for the last iteratio

Language extension idea (was Re: [Haskell-cafe] Re: OCaml list sees...)

2004-10-09 Thread oleg
Tom Pledger wrote: > Something along these lines: > > class List l a | l -> a where > nil :: l > cons :: a -> l -> l > > But that's not of much use, because there isn't a class method to > recover the elements of a List. We could add more methods (corresponding > to null, head

Re: [Haskell-cafe] existential type problem

2004-10-22 Thread oleg
> > data Bar a m = forall t. (MonadTrans t, Monad (t m)) => > > Bar (t m a -> m a) (t m Int) > > data Foo = Foo (forall a m. Monad m => Bar a m) > > Is it true that I cannot have a function > > foo run op = Foo (Bar run op) I guess the answer is yes and no. Let's consider the ty

[Haskell-cafe] Re: Are handles garbage-collected?

2004-10-25 Thread oleg
Simon Marlow wrote: > I've been wondering whether having a more synchronous kind of > finalizer would be a good thing. Hans Boehm in his POPL2003 paper "Destructors, Finalizers, and Synchronization" persuasively argued that finalizers _must_ be asynchronous. That assertion is the title of Section

[Haskell-cafe] Re: Lexically scoped type variables

2004-11-26 Thread oleg
Simon Peyton-Jones wrote: > In GHC at present, a separate type signature introduces no scoping. For > example: > f :: forall a. a -> a > f x = (x::a) > would be rejected, because the type signature for 'f' does not make > anything scope over the right-hand side, so (x::a) means (x

Re: [Haskell-cafe] Equality of functions

2004-11-30 Thread oleg
Jules Bean wrote: > From the point of view of a programmer, that's all there is to it: > there is no way of proving two functions are the same except by > exhaustively checking every input. That is too pessimistic, I'm afraid. There is also an intensional equality. Granted, it can be sound but

[Haskell-cafe] The difference between ($) and application

2004-12-13 Thread oleg
The operator ($) is often considered an application operator of a lower precedence. Modulo precedence, there seem to be no difference between ($) and `the white space', and so one can quickly get used to treat these operators as being semantically the same. However, they are not the same in all ci

[Haskell-cafe] Re: Typed Lambda-Expressions withOUT GADTs

2005-01-01 Thread oleg
Ashley Yakeley wrote on the first day of 2005: > This compiled with today's CVS GHC 6.3. I don't think you can do this > without GADTs. It seems we can do without GADT -- roughly with the same syntax (actually, the syntax of expressions is identical -- types differ and we have to write `signature

[Haskell-cafe] Re: Typed Lambda-Expressions withOUT GADTs

2005-01-03 Thread oleg
class. OTH, if we place the handlers in a HList, and use the OOHaskell encoding, we can probably arrive at open (extensible) GADT. The complete new code is included. > Where now? Well, counterexample fiends who want to provoke Oleg into > inventing a new recipe had better write down a higher-or

[Haskell-cafe] Problem with fundeps.

2005-01-03 Thread oleg
On Sun, 2 Jan 2005 [EMAIL PROTECTED] wrote: > I tried to generalize one of my old > packages for quantum *abstract* computations, where state vectors are > defined as functional objects, whose codomain has some arithmetic. > It is easy to see that you can define (f <+> g) = \x -> f x + g x > etc.

[Haskell-cafe] Initial (term) algebra for a state monad

2005-01-04 Thread oleg
Andrew Bromage wrote: << -- WARNING: This code is untested under GHC HEAD data State s a = Bind :: State s a -> (a -> State s b) -> State s b | Return :: a -> State s a | Get :: State s s | Put :: s -> State s () instance Monad (State s) where (>>=) = Bind return = Return insta

[Haskell-cafe] Re: Point-free style (Was: Things to avoid)

2005-02-10 Thread oleg
the categorical product. The second example is taken from http://pobox.com/~oleg/ftp/Haskell/categorical-maxn.lhs which has the following comment about that code fragment: The constraints in the prod's type are intricately related. The final expression for prod bears some similarity with Un

[Haskell-cafe] Automatic pointless translation

2005-02-14 Thread oleg
This message is a literate Haskell98 code for translating proper linear combinators into a point-free style. That is, we will be converting (closed, albeit that is not strictly a requirement) terms of the form ``\x1 ... xn -> term'' where each variable xi has at most one occurrence in term. The te

[Haskell-cafe] Re: (Newbie) Dynamic Programming, Memoizing Etc.

2005-03-16 Thread oleg
Bryce Bockman wrote: > How would you guys memoize the following code. > > simpleCalc :: (Int,Int) -> (Int,Int) > simpleCalc (1,l) = (1,l+1) > simpleCalc (x,l) | (odd x) = simpleCalc (((3*x) + 1), 1 + l) > | otherwise = simpleCalc ((x `div` 2), 1 + l) > > sCalc x = simpleCalc (x,

[Haskell-cafe] Re: Best practices for modular programming in Haskell

2005-03-16 Thread oleg
Benjamin Pierce wrote: > For someone coming to Haskell from an OCaml background, one of the hardest > things to get used to is the somewhat more bare bones module system that > Haskell provides. > ... > This works fine as long as what you're exporting is just values, but it's > awkward for types,

[Haskell-cafe] Re: working Edison, a couple of collection modules, and typing troubles

2005-05-25 Thread oleg
Samuel Bronson wrote: > I was trying my hand at writing some collection classes myself and I > can't figure out a good typing for map that will let me make Map an > instance of my Collection class... > I don't much like the head of Mapping. How about the following: > class Collection (d k e) (k

[Haskell-cafe] Re: working Edison, a couple of collection modules, and typing troubles

2005-05-26 Thread oleg
> This also doesn't seem like it would work very well with making an > instance for IntMap. > I guess I can't have everything. It is not that difficult to make instances for IntMap: > data TypeCast k IM.Key => WIM k e = WIM (IM.IntMap e) deriving Show > > instance Collection (WIM IM.Key e) (IM.K

[Haskell-cafe] Simulating OO programming with type classes; writing a factory fu nction

2005-05-31 Thread oleg
Alistair Bayley wrote: > There's a small problem: how to write a factory function that returns values > of various subtypes. The makeSubType function below won't compile, obviously > because the returns types are different (they're not the same 'm'). Indeed, expressions in both branches of an `i

[Haskell-cafe] Re: Control.Monad.Cont fun

2005-07-07 Thread oleg
utStrLn "finish") Delimited continuations are really cool. The lack of the answer-type polymorphism in ContT will come to bite us in the end: we can't use reset several times in differently-typed contexts (which often means that we can use reset only once in our program). The CC monad t

RE: [Haskell-cafe] Overlapping Instances with Functional Dependencies

2005-07-11 Thread oleg
Daniel Brown wrote: >class Baz a b | a -> b >instance Baz (a -> b) (a -> [b]) >instance Baz a a > ...but Baz fails with this error... > > When confronted with overlapping instances, the compiler chooses the > most specific one (if it is unique), e.g. `Baz (a -> b) (a -> [b])` is > mor

[Haskell-cafe] Re: Lists vs. Monads

2005-07-16 Thread oleg
he paper specifically made a point that msplit can be defined without help from recursive data types. The brief summary of that derivation is a note `How to take a TAIL of a functional stream' http://pobox.com/~oleg/ftp/Computation/Continuations.html#cdr-fstream The higher-rank ty

[Haskell-cafe] Re: [Haskell] Re: A MonadPlusT with fair operations and pruning

2005-07-18 Thread oleg
Regarding the law of mif (aka ifte, aka soft-cut, aka logical conditional) mif (mif c t' e') t e = mif c (\x -> mif (t' x) t e) (mif e' t e) You're right of course: mode matters for the predicates that involve negation, such as mif. However, I believe that the mode is orthogonal to the disc

Re: [Haskell-cafe] Re: Lists vs. Monads

2005-07-21 Thread oleg
Jonathan Cast wrote: ] > You can't define most initial models without recursive (or ] > inductive) data types in general, because initial models are defined ] > inductively. ] > You can't define head, tail, or foldr using the MonadPlus ] > signature ] OK. Right. I forgot about the Church en

[Haskell-cafe] Control.Monad.Cont fun

2005-07-25 Thread oleg
On Thu, Jul 07, 2005 at 07:08:23PM +0200, Tomasz Zielonka wrote: > Some time ago I wanted to return the escape continuation out of the > callCC block, like this: > > getCC = callCC (\c -> return c) It seems using shift/reset is better not only in principle but in practice as well. > module Foo

[Haskell-cafe] A better, fair, and terminating backtracking monad [Was: Concurrency question]

2005-09-04 Thread oleg
For example, http://pobox.com/~oleg/ftp/Computation/monads.html#fair-bt-stream First of all, the monad can let succeed the computations that surely diverge in List and similar monads. As the code at the end of that file shows, the monad avoids depth-first traps, and can even handle left-r

[Haskell-cafe] Generic parser without GADTs

2005-10-16 Thread oleg
Also inspired by Ralf Hinze's post, I thought of removing GADTs from that code. The result is Haskell98! code, which works well in Hugs. The code seems to be a bit simpler too. Like the original code, the function 'parseAny' correctly discriminates between the list of characters (i.e., strings) an

[Haskell-cafe] Regular Expressions without GADTs

2005-10-17 Thread oleg
Conor McBride wrote: > Inspired by Ralf's post, I thought I'd just GADTize a dependently typed > program I wrote in 2001. Equally inspired, I thought of deGADTizing that code. The code below also uses no existentials, and no local type annotations. The code is more general in that the parser wor

Re: [Haskell-cafe] Regular Expressions without GADTs

2005-10-18 Thread oleg
Conor McBride wrote: > Neither Oleg nor Bruno translated my code; they threw away my > structurally recursive on-the-fly automaton and wrote combinator parsers > instead. That's why there's no existential, etc. The suggestion that > removing the GADT simplifies th

Re: [Haskell-cafe] Regular Expressions without GADTs

2005-10-18 Thread oleg
Conor McBride wrote: > Neither Oleg nor Bruno translated my code; they threw away my > structurally recursive on-the-fly automaton and wrote combinator parsers > instead. That's why there's no existential, etc. The suggestion that > removing the GADT simplifies th

[Haskell-cafe] Typeclasses and GADT [Was: Regular Expressions without GADTs]

2005-10-18 Thread oleg
Ralf Hinze wrote: > To me replacing a GADT by class and instance declarations seems the > wrong way round. We should not forget that the DT in GADT stands for > `data type'. Francois Pottier enumerated some problems with type inference of GADT code during his ICFP'05 invited talk. Various extensi

[Haskell-cafe] Re: Typeclasses and GADT [Was: Regular Expressions without GADTs]

2005-10-26 Thread oleg
Tomasz Zielonka wrote: > Speaking about casts, I was playing with using GADTs to create a > non-extensible version of Data.Typeable and Data.Dynamic. > I wonder if it's possible to write such a thing without GADTs (and > unsafeCoerce, which is used in Data.Dynamic, IIRC). Absolutely. Stephanie W

[Haskell-cafe] Problem with continuations and typing

2005-12-01 Thread oleg
similar model, I could inspire > myself on? (I know a few theoretical works on that). Yes, of course: the code for the LogicT paper http://pobox.com/~oleg/ftp/packages/LogicT.tar.gz (please see SFKT.hs) and http://www.haskell.org/pipermail/haskell/2005-October/016577.html http://

[Haskell-cafe] GADT question

2005-12-05 Thread oleg
John Meacham wrote: > data Type = ForAll [TyVar] Rho -- Forall type > | FunType Type -- Function type > | TyCon TyCon -- Type constants > | TyVar TyVar -- Always bound by a ForAll > with the three synonyms and their constraints being

[Haskell-cafe] how to nicely implement phantom type coersion?

2005-12-08 Thread oleg
David Roundy wrote: ] The basic idea is that a patch will have type (Patch a b) where "a" and "b" ] are phantom types. Sequential patches will have identical ending and ] beginning types. So that a sequential pair, for example, can be written as ] ] data Sequential a c where ] Sequential ::

[Haskell-cafe] Re: Announcing Djinn, version 2004-12-11, a coding wizard

2005-12-14 Thread oleg
Stefan Monnier wrote: > I expected at first you were doing some funky type class molestation > so you can use "djinn" in your code and let Haskell fill it in. That has already been done: De-typechecker: converting from a type to a term http://www.haskell.org/pipermail/haskell/2005-March/015423.h

Re: Lambda over types.

2002-04-05 Thread oleg
t (x y z ...), x is not an appl and not an abst ; It is equivalent to ((x y) z ...) ; Try to reduce y, z, etc. separately Eval (x y . rest) -> (A x (Map Eval (y . rest))) ; The topmost is (x) -- remove the extra parens Eval (term) -> Eval term E

Naming conventions for compiler options [Was: layout rule infelicity]

2002-05-30 Thread oleg
[redirected to haskell-cafe] Jón Fairbairn wrote: > 1. Why "-f" anyway? It took me ages to work out what > "-fallow-overlapping-instances" meant -- I wondered how > "fallow" could apply to overlapping instances. I believe the authors of GHC followed the naming conventions of GCC, which can be g

Haskell is more known than we might think

2002-07-29 Thread oleg
Hello! The other day I received, among other junk mail, coupons for the local 7-eleven store. I subconsciously scanned the envelope, and almost jumped when I read the return address: 7-Eleven, Inc. 2711 North Haskell Avenue Dallas, TX 75204 It seems a rather long Avenue

Transformations of cyclic graphs [Was: Efficiency of list indices in definitions]

2002-08-08 Thread oleg
[Moved to Haskell-Cafe] Hello! Cycles sure make it difficult to transform graphs in a pure non-strict language. Cycles in a source graph require us to devise a way to mark traversed nodes -- however we cannot mutate nodes and cannot even compare nodes with a generic ('derived') equality operato

Re: Fw: Question about the use of an inner forall

2002-08-20 Thread oleg
> Leon Smith wrote: > >On Friday 16 August 2002 23:57, Scott J. wrote: > >runST :: forall a ( forall s ST s a) -> a ? > > > >In logic forall x forall y statement(x.y) is equivalent to: > > forall y forall x statement(x,y). > Now, using a different argument, since "s" does not appear free on >

Re: Pure File Reading (was: Dealing with configuration data)

2002-09-26 Thread oleg
There is another solution to the problem of configurational parameters. The main part of the solution is portable, does not depend on any pragmas, does not use unsafe operations, does not use implicit parameters, and does not require any modifications to the user code. I must warn that it is also

De-biforestation

2002-12-03 Thread oleg
Deforestation is usually defined as the elimination of an intermediate data structure between a single producer and a single consumer. Jorge Adriano showed an interesting example of one producer feeding two independent consumers. The two streams of data are mutually dependent. Furthermore, the rat

Re: Interpret haskell within haskell.

2002-12-20 Thread oleg
David J. Sankel wrote: > I was referring to a haskell interpreter to be used > within haskell code. For instance: > main = do > user_configuration <- parseHaskell > title <- resolveFunction user_configuration "title" > :: String > putStr title This was exactly the gist of the message: ht

Re: Interpret haskell within haskell.

2002-12-23 Thread oleg
Lauri Alanko wrote on Dec 22: > The magic is _here_: > (begin (define a 5) (eval '(set! a (+ a 1)) (interaction-environment)) a) > ==> 6 > Here (interaction-enviroment) is a run-time representation of the > compile-time environment. It makes possible two-way interaction between the > stages. Ess

Re: Global variables?

2003-02-03 Thread oleg
Richard Uhtenwoldt wrote: > (2) the global variable has a lexical scope that extends over > the bulk of the program. > It strikes me as a simple and obvious application of lexical > scope, and I am surprised that it received no mention in the > discussions on this list and in Hughes's paper. Som

Re: arrays and lamda terms

2003-02-04 Thread oleg
Cagdas Ozgenc wrote: > Is it possible to encode an array using lamda terms only, and recover > the term specified by an index term in O(1) time? I'd like to go on a limb and argue that there is generally no such thing as O(1) array access operation. On the conventional hardware, the fastest acce

Re: speedup help

2003-03-06 Thread oleg
| comb is only called from here: | sumbn n = sum [ bernoulli i * fromIntegral(comb (n+1) i) | i | <- [0 .. n-1] ] Probably I misunderstand what "bernoulli i" stands for. If it is meant Bernoulli number B_i, http://mathworld.wolfram.com/BernoulliNumber.html then the above expression is qu

Re: speedup help

2003-03-07 Thread oleg
> Oleg's blew the heap at 847; mine valiantly struggled on 'til it blew > the heap at 1910. Hmm, I managed to compute bernoulli 2000 and even bernoulli 3000. The code is included. It took 7 minutes (2GHZ Pentium IV, 1GB memory) to compute bernoulli 2000 and 33 minutes for bernoulli 3000. I monito

Redefining methods in a subCLASS

2003-03-14 Thread Oleg
Hi Is it possible to redefine methods in a subclass (not an instance)? E.g. I get errors in class (Show a) => Employee a where speak :: a -> [Char] speak x = "Employee: " ++ (show x) class (Employee a) => Manager a where speak x = "Manager: &q

Powerset

2003-06-10 Thread oleg
The following seems to be a faster version of powerset that delivers results strictly in the order of increasing cardinality (i.e., all sets of size 1 first, then of size 2, etc). It seems to run faster than any other ordered version of powerset posted so far. On GHCi, length $ powerset [1..22] is

<    1   2   3   4   5   >