RE: [Haskell-cafe] checking types with type families

2010-07-01 Thread Eduard Sergeev
Simon Peyton-Jones wrote: I'm interested in situations where you think fundeps work and type families don't. Reason: no one knows how to make fundeps work cleanly with local type constraints (such as GADTs). If you think you have such as case, do send me a test case. As an example, is

Re: [Haskell-cafe] list - sublists

2009-10-21 Thread Eduard Sergeev
satorisanitarium wrote: How to make a list of sublists out of a list, whether they be a list of numbers or a string. Without recursion (with fold) starting from the tail of the input list: foo n = foldr st [[]] where st x xss | x == n = [x]:xss st x (xs:xss) =

Re: [Haskell-cafe] Observer pattern in Haskell?

2009-11-09 Thread Eduard Sergeev
Andy Gimblett-2 wrote: To help manage dependencies between state and UI elements, I looked for a Haskell version of the Observer design pattern Isn't Reactive Programming approach more suitable than Observer if we talk about Haskell? -- View this message in context:

Re: [Haskell-cafe] Observer pattern in Haskell?

2009-11-09 Thread Eduard Sergeev
Andy Gimblett-2 wrote: Possibly. Care to expand? If you have a more elegant solution, which fits in well with ordinary wxHaskell, I'd be interested. I believe there are a few experimental frameworks built on top of wxHaskell which use Functional Reactive Programming, like

Re: [Haskell-cafe] Help to solve simple problem !

2009-11-10 Thread Eduard Sergeev
Aneto wrote: compress :: Eq a = [a] - [(a, Int)] If you have string AAABCCC it transforms it to : {A, 3} {B,1} {C,3} Basically you need to group equal elements of the list first and then transform every group (which is a list of equal elements) to the tuple of (first_element , the_

Re: [Haskell-cafe] Are functional dependencies around to stay?

2009-12-22 Thread Eduard Sergeev
G√ľnther Schmidt wrote: I'm wondering if there is any chance that functional dependencies will not be around in the future. As was previously noted they are supposed to be replaced by type families, but for me the crucial difference between these two now is that currently type families do not

Re: [Haskell-cafe] Are functional dependencies around to stay?

2009-12-22 Thread Eduard Sergeev
Hi Stephen, Stephen Tetley-2 wrote: Currently this seems a more like a rumour than a fact - from [1] Type Families and Fun Deps are equivalently expressive which seems a worthwhile point to restate. I've got the same impresion initially and was keen to use TF in favor to FD. And I'm

Re: [Haskell-cafe] Language simplicity

2010-01-12 Thread Eduard Sergeev
Andrew Coppin wrote: OK people, it's random statistics time! OK, my version of meaningless statistics: C++ (ISO/IEC 14882:1998(E)): 325 pages (712 including standard libraries) C# (ECMA-334): 505 pages (language only) Java: 450 pages (language only?) Scala (2.7): 125 pages (157 including

Re: [Haskell-cafe] Spelling checker exercise

2010-01-26 Thread Eduard Sergeev
Matthew Phillips-5 wrote: I also found it to to be very slow. My variant: http://a-ejeli-tak.livejournal.com/1326.html Spellchecker in Haskell String version runs in 2.5 sec, ByteString in 1.2 sec (just for one word e.g. just to build the tree). 8 sec to check input of 400 words (copied from

Re: [Haskell-cafe] foldl in terms of foldr

2010-01-26 Thread Eduard Sergeev
Xingzhi Pan wrote: The first argument to foldr is of type (a - b - a), which takes 2 arguments. But 'step' here is defined as a function taking 3 arguments. What am I missing here? You can think of step as a function of two arguments which returns a function with one argument (although

Re: [Haskell-cafe] Spelling checker exercise

2010-01-26 Thread Eduard Sergeev
Daniel Fischer-4 wrote: But that's the point, these checks aren't unnecessary (unless the word under inspection is known). You want to propose the most likely correct word. I just wanted to rewrite original Nornig's Python code in Haskell :) (maybe I misunderstood the algorithm?). Of

Re: [Haskell-cafe] foldl in terms of foldr

2010-01-26 Thread Eduard Sergeev
Neil Brown-7 wrote: step is of type b - (a - a) - (a - a), which does agree with (a - b - b) Not quite right.. Let's rewite the function: myFoldl f z xs = foldr (step f) id xs z step f x g = \a - g (f a x) now (from ghci): step (+) :: (Num t1) = t1 - (t1 - t3) - t1 - t3 or even: step

Re: [Haskell-cafe] foldl in terms of foldr

2010-01-26 Thread Eduard Sergeev
Xingzhi Pan wrote: More over, does foldr step f id xs z equal to foldr (step f) id xs z?? No, it does not. The former passes three-argument function 'step' to foldr and the later passes two-argument function which is the result of the partial application (step f). -- View this message in

Re: [Haskell-cafe] foldl in terms of foldr

2010-01-26 Thread Eduard Sergeev
Eduard Sergeev wrote: The former passes three-argument function 'step' to foldr and the later passes two-argument function which is the result of the partial application (step f). Correction :) 4-arg and 3-arg respectively. -- View this message in context: http://old.nabble.com/foldl

Re: [Haskell-cafe] type class constraints headache

2010-03-04 Thread Eduard Sergeev
Related question probably: why ghc compiles this: {-# LANGUAGE RankNTypes, ImpredicativeTypes #-} methods :: [(String, forall b. Eq b = b)] methods = [ (method1, undefined ) , (method2, undefined) ] test:: [String] test= pmap methods where pmap = map fst But when I change

[Haskell-cafe] Deepest polymorphic functor

2009-07-28 Thread Eduard Sergeev
I was wondering if it is possible to somehow change deep f_map from http://okmij.org/ftp/Haskell/deepest-functor.lhs article in a such a way that it would work not only for monotypes like in the provided example: test1 = f_map (+1) [[[1::Int,2,3]]] But for polymorphic types as well (e.g.

Re: [Haskell-cafe] Deepest polymorphic functor

2009-07-30 Thread Eduard Sergeev
Ryan Ingram wrote: What would this do with instance Num a = Num [a] in scope? It should work not only for Num a anyway (like normal Functor would do) but if you could give me an example, how exactly could I use Num a here... -- View this message in context:

Re: [Haskell-cafe] Deepest polymorphic functor

2009-07-30 Thread Eduard Sergeev
PS In regards to the original http://okmij.org/ftp/Haskell/deepest-functor.lhs Am I right that the following code from the sample: class IsCollection t coll | t - coll instance IsCollection (m a) (m ()) instance TypeCast Atom coll = IsCollection t coll class TypeCast a b | a - b, b-a

Re: [Haskell-cafe] Deepest polymorphic functor

2009-07-31 Thread Eduard Sergeev
Ryan Ingram wrote: The problem is this: instance Num a = Num [a] where ... test = deep_fmap (+1) [[[ 1, 2, 3 :: Int ]]] What (+1) should be used? (+1) :: Int - Int (+1) :: [Int] - [Int] (+1) :: [[Int]] - [[Int]] (+1) :: [[[Int]]] - [[[Int]]] They could all be type-correct, so

Re: [Haskell-cafe] Deepest polymorphic functor

2009-07-31 Thread Eduard Sergeev
Ryan Ingram wrote: instance Num a = Num [a] where ... O... I see what you mean. So... no way around? e.g. no way to define deep_fmap for not grounded types? -- View this message in context: http://www.nabble.com/Deepest-polymorphic-functor-tp24709303p24752047.html Sent from the Haskell

Re: [Haskell-cafe] convert a list of booleans into Word*

2009-09-30 Thread Eduard Sergeev
Bulat Ziganshin-2 wrote: sum . zipWith (*) (map (2^) [0..]) foldr1 $ \b - (+b) . (*2) -- View this message in context: http://www.nabble.com/convert-a-list-of-booleans-into-Word*-tp25677589p25686400.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

Re: [Haskell-cafe] river crossing puzzle

2009-09-30 Thread Eduard Sergeev
pat browne-2 wrote: Hi, Does anyone know where there are any Haskell implementations of the the River Crossing puzzle (AKA Farmer/Fox/Goose/Grain). Here is an implementation of the similar problem with good explanation (see PDF): http://web.engr.oregonstate.edu/~erwig/zurg/ It isn't

Re: [Haskell-cafe] Programming Chalenges: The 3n+1 problem

2011-04-14 Thread Eduard Sergeev
Hi Dmitri, *** Question: I wonder how to implement cache for this problem in Haskell? At the moment, I am not so much interested in the speed of the code, as in nice implementation. Yet another option for memoization implementation: to use monad-memo package [1] which provides memoization for