Re: [Haskell-cafe] memorize function with number parameterized types in GHC

2011-11-06 Thread DavidA
What's the purpose of all the type trickery? Why not just implement the algorithm using Integer? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Re: [Haskell-cafe] memorize function with number parameterized types in GHC

2011-11-06 Thread DavidA
modulus, but the modulus won't be changed within Num typeclass. It's better to fix it in type system. On Nov 7, 2011 1:38 AM, DavidA polyomino at f2s.com wrote: What's the purpose of all the type trickery? Why not just implement the algorithm using Integer

Re: [Haskell-cafe] Type Constraints on Data Constructors

2011-06-09 Thread DavidA
Malcolm Wallace malcolm.wallace at me.com writes: data Bar f a = Foo f = Bar {bar :: f a} The class context on the data constructor buys you nothing extra in terms of expressivity in the language. All it does is force you to repeat the context on every function that uses the

[Haskell-cafe] Re: Decoupling type classes (e.g. Applicative)?

2010-10-29 Thread DavidA
I've been thinking about the following type class design principles: * Only include two functions in the same design class if both can be implemented in terms of each other. * Only introduce a dependency from type class A to type class B if all functions in type class B can be

[Haskell-cafe] Re: A rant against the blurb on the Haskell front page

2010-10-18 Thread DavidA
Ketil Malde ketil at malde.org writes: Don Stewart dons at galois.com writes: Good start, if only the advanced were replaced with something more characteristic, like lazy, or statically typed. Which, BTW, both do not lazy and statically typed don't mean much to other people. They are

[Haskell-cafe] Monad instance for partially applied type constructor?

2010-09-29 Thread DavidA
Hi, I have the following code: {-# LANGUAGE TypeSynonymInstances #-} data Vect k b = V [(k,b)] -- vector space over field k with basis b -- for example, V [(5, E 1), (7, E 2)] would represent the vector 5 e1 + 7 e2 data Monomial v = M [(v,Int)] -- monomials over variables v -- for example, M

[Haskell-cafe] Re: Monad instance for partially applied type constructor?

2010-09-29 Thread DavidA
Ryan Ingram ryani.spam at gmail.com writes: Haskell doesn't have true type functions; what you are really saying is instance Monad (\v - Vect k (Monomial v)) Yes, that is exactly what I am trying to say. And since I'm not allowed to say it like that, I was trying to say it using a type

[Haskell-cafe] Type families - how to resolve ambiguities?

2010-08-25 Thread DavidA
Hi, The code below defines a type synonym family: {-# LANGUAGE MultiParamTypeClasses, TypeFamilies #-} {-# LANGUAGE FlexibleInstances, TypeSynonymInstances #-} data Vect k b = V [(b,k)] deriving (Eq,Show) data TensorBasis a b = T a b deriving (Eq, Ord, Show) type family Tensor k u v :: *

[Haskell-cafe] Re: Equality constraints and RankNTypes - how do I assist type inference

2010-08-21 Thread DavidA
Brandon S Allbery KF8NH allbery at ece.cmu.edu writes: type Tensor u v = (u ~ Vect k a, v ~ Vect k b) = Vect k (TensorBasis a b) -- ** IIRC this actually substitutes as (forall k a b. (u ~ Vect k a, v ~ Vect k b) = Vect k (TensorBasis a b)) and the implicit forall will

[Haskell-cafe] Equality constraints and RankNTypes - how do I assist type inference

2010-08-20 Thread DavidA
Hi, I have the following code, using equality constraints and (I believe) RankNTypes: {-# LANGUAGE MultiParamTypeClasses, TypeFamilies, RankNTypes, ExistentialQuantification #-} {-# LANGUAGE FlexibleInstances, TypeSynonymInstances #-} -- import Math.Algebra.Group.PermutationGroup --

[Haskell-cafe] Nested unsafePerformIO?

2010-04-08 Thread DavidA
Hi, I am having difficulty debugging a troublesome stack overflow, which I think might be related to calling unsafePerformIO from within the IO monad. So I have the following code: import System.Random import System.IO.Unsafe import Data.Time.Clock timedIterateIO :: Int - (a - a) - a - IO a

[Haskell-cafe] Re: Nested unsafePerformIO?

2010-04-08 Thread DavidA
Bas van Dijk v.dijk.bas at gmail.com writes: It looks like your timedIterateIO is too lazy. Try evaluating the 'y' before calling timedIterateIO' again as in: let y = f x ... y `seq` timedIterateIO' t0 y Thank you, that appears to do the trick. I'm still a bit puzzled about why the

[Haskell-cafe] What is

2009-09-22 Thread DavidA
Hi, When I try to build my HaskellForMaths library (http://hackage.haskell.org/package/HaskellForMaths) using GHC6.10.4 on Mac OS X (Leopard), I get several ld warning: atom sorting error (see below). The same code built without problems under GHC6.10.3 on Windows. The code in question is using

[Haskell-cafe] Inconsistency in support for phantom types?

2009-01-08 Thread DavidA
Hi, I have run into what appears to be an inconsistency in the support for using phantom types to parameterize other types. Here's an example (don't pay too much attention to the maths, it's just there to motivate the example). I want to define types for the finite fields with 2, 3 and 5 elements

[Haskell-cafe] Re: Unique functor instance

2008-11-25 Thread DavidA
Luke Palmer lrpalmer at gmail.com writes: I've been wondering, is it ever possible to have two (extensionally) different Functor instances for the same type? I do mean in Haskell; i.e. (,) doesn't count. I've failed to either come up with any examples or prove that they all must be the

[Haskell-cafe] Re: Unique functor instance

2008-11-25 Thread DavidA
Janis Voigtlaender voigt at tcs.inf.tu-dresden.de writes: DavidA wrote: I suspect that the answer to the question is, yes, you can have different Functor instances. All you need is a sum-product type that it's possible to interpret as two different abstractions, leading to two

[Haskell-cafe] Re: universal algebra support in Haskell?

2008-10-23 Thread DavidA
Num is basically Ring, but is spoiled by the inclusion of abs and signum, which of course mainly only make sense for subrings of C. Hello, I see that there is a Monoid class from Data.Monoid. What other algebras like Group, Ring, etc. have support in Haskell?Thanks, Vasili

[Haskell-cafe] Re: type classes

2008-07-03 Thread DavidA
Slightly off-topic - but I'm curious to know why you want objects representing the structures as well as the elements - what will they be used for? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org

[Haskell-cafe] How do I simulate dependent types using phantom types?

2007-08-18 Thread DavidA
Hi, I am trying to implement quadratic fields Q(sqrt d). These are numbers of the form a + b sqrt d, where a and b are rationals, and d is an integer. In an earlier attempt, I tried data QF = QF Integer Rational Rational (see http://www.polyomino.f2s.com/david/haskell/hs/QuadraticField.hs.txt)

[Haskell-cafe] Re: How do I simulate dependent types using phantom types?

2007-08-18 Thread DavidA
Twan van Laarhoven twanvl at gmail.com writes: The solution is to use a dummy parameter: class IntegerType a where value :: a - Integer And call it like: f = value (undefined :: Two) So for instance: instance IntegerType d = Show (QF d) where show (QF a b) = show a ++

[Haskell-cafe] Type classes: Missing language feature?

2007-08-07 Thread DavidA
Hi, there's something I'm trying to do with type classes that seems to fit very naturally with my mental model of type classes, but doesn't seem to be supported by the language. I'm wondering whether I'm missing something, or whether there's some language extension that could help me or

[Haskell-cafe] Re: partitions of a multiset

2007-07-25 Thread DavidA
It seems to me (unless I've missed something?) that this method generates the power set of the original multiset (i.e. all subsets) rather than partitions.  Oops, sorry, wasn't concentrating. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org

[Haskell-cafe] Re: partitions of a multiset

2007-07-23 Thread DavidA
Here's the approach I would try. 1. Use Data.List.group to group your multiset, eg [1,1,2] - [[1,1],[2]] 2. Now apply your partitions function to each of the groups [[1,1],[2]] - [ [([1,1],[]), ([1],[1]), ([],[1,1])], [([2],[]), ([],[2])] ] (Actually of course, you can probably write a simpler

[Haskell-cafe] Re: Finding points contained within a convex hull.

2007-06-07 Thread DavidA
It's been a while, but I believe that you can solve integer programming problems of this type using Groebner bases. (Google for integer programming with Groebner bases). I have some Groebner basis code in Haskell at http://www.polyomino.f2s.com/david/haskell/commalg.html

[Haskell-cafe] Re: Why does the class called Real support only rationals, and not all reals?

2007-06-04 Thread DavidA
Yes, I'm afraid that you are understanding correctly. Annoying isn't it. It is well-known (among Haskell mathematicians at least) that the numeric type classes in the prelude are broken. Here's one proposal for a small step in the right direction:

[Haskell-cafe] Re: Higher order types via the Curry-Howard correspondence

2007-05-11 Thread DavidA
Gaal Yahas gaal at forum2.org writes: What do higher-order types like lists mean when viewed through the Curry-Howard correspondence? Okay well I don't know the complete answer, but since no one else has answered I'll have a go. Suppose we define our own version of list as data List a =

[Haskell-cafe] Re: 'Proper' use of the State monad

2007-05-01 Thread DavidA
1) Using State GameState r and then call execState for each game event (i.e. user input) so I can do IO 2) Using StateT GameState IO () and have the entire game live in one big execStateT call. (I note XMonad does something similar.) I'm also interested in the answer to this question. One

[Haskell-cafe] Re: How Albus Dumbledore would sell Haskell

2007-04-19 Thread DavidA
Simon Peyton-Jones simonpj at microsoft.com writes: But, just to remind you all: I'm particularly interested in concrete examples (pref running code) of programs that are * small * useful * demonstrate Haskell's power * preferably something that might be a

[Haskell-cafe] Re: A wish for relaxed layout syntax

2007-03-29 Thread DavidA
Andrzej Jaworski himself at poczta.nom.pl writes: Perhaps you can also figure out how to replace the disturbing $ operator? I suggest in place of $. For example: h x = f g x ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org

[Haskell-cafe] How do I do conditional tail recursion in a monad?

2007-03-21 Thread DavidA
Hi, I would like to write a function untilM, which would be to until as mapM is to map. An example use would be if I had a function dice :: State Int Int which returns random dice throws within a state monad. Then I'd like to be able to do something like untilM (\(s,p)- s=100) f (0,1)

[Haskell-cafe] Re: Two Other AI Sources

2007-03-20 Thread DavidA
I would also recommend Mitchell, Machine Learning. I have quite a lot of Haskell code for stuff in this book, which I'm currently polishing for publishing. (For example, I'm rather proud of my thirty line neural network code.) ___ Haskell-Cafe

[Haskell-cafe] Re: How do I avoid stack overflows?

2007-03-17 Thread DavidA
Hi, Thanks for the suggestions. A few more questions. The (*) function is just one of a number of lazy matrix arithmetic functions that I have. If I need them to be evaluated strictly, is it best to modify the matrix code, or the code that's calling it? In this case, it looks like I can fix

[Haskell-cafe] How do I avoid stack overflows?

2007-03-15 Thread DavidA
Hi. I'm trying to write some code which involves lots of matrix multiplications, but whenever I do too many, I get stack overflows (in both GHCi 6.4.2, and Hugs May 2006). The following code exhibits the problem. import List (transpose) u . v = sum $ zipWith (*) u v a * b = multMx a

[Haskell-cafe] Re: Optimization fun

2007-02-12 Thread DavidA
Lennart Augustsson lennart at augustsson.net writes: Yes, and that's pretty much what my version does (and what the original tried to do?). Yes, you're right, I see now that my method is equivalent to yours. (My apologies, it was late.) The point I was trying to make is that there are two

[Haskell-cafe] Re: Optimization fun

2007-02-11 Thread DavidA
If you want it fast, don't use a sieve method at all (or a wheel method) - use trial division: primes = 2 : [p | p - [3,5..], trialDivision primes p] trialDivision (p:ps) n | r == 0= False | q p = True | otherwise = trialDivision ps n

[Haskell-cafe] Re: Permutation with k levels

2006-11-07 Thread DavidA
What you're trying to do is called permutations with repetition, whereas permutations (unqualified) usually refers to permutations without repetition (and that's what the Haskell code you found is doing). See http://en.wikipedia.org/wiki/Permutations_and_combinations To get the result you