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
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
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
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
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
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
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
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 :: *
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
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
--
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
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
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
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
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
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
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
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
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)
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 ++
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
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
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
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
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:
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 =
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
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
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
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)
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
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
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
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
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
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
36 matches
Mail list logo