Haskell help!
Andrew J Bromage
ajb@spamcop.net
Thu, 27 Mar 2003 10:04:40 +1100
G'day.
Some general advice...
On Wed, Mar 26, 2003 at 04:30:08PM -0600, Weix, Rachel Lynn wrote:
> Currently I'm having problems with type checking due to Haskell being
> a strongly typed language.
Problems with type checking are almost never caused by Haskell being
a strongly typed language. (Note to the peanut gallery: I did say
_almost_ never.)
Problems with type checking are generally caused by one of 1) your
program has a bug, or 2) you don't understand your program as well
as you think you do. (This is no reflection on you, incidentally.
The best programmers are often surprised by their own code.)
> In order to return all optimal solutions,
> my professor suggested I create a list of tuples if they all have the
> same score, as indicated in my new maxSeq method (see attachment).
> However, this means that the maxSeq method would return type
> [[(Char,Char)]]. Since maxSeq and getSeq must return the same type,
> I end up changing all my signatures and end up with lots of problems.
You can save yourself a lot of grief by using type synonyms. If, as
in your case, you have two functions which must return the same thing
but that thing may change while the program is being written or
maintained, a type synonym is precisely what you need. Change it once,
and all your type declarations change with it.
By the way, your examples aren't valid Haskell. This, for example:
> [ [(-,M)(T,a)(h,s)(-,t)(e,e)(-,r)(-,s)], [(-,M)(T,a)(-,s)(h,t)(e,e)(-,r)(-,s)] ]
won't compile. You may like to come up with some concrete examples,
put them in your script, then write code which tests the functions
that you have written using those examples. If nothing else, the
act of writing the examples in valid Haskell may help clarify your
thinking a bit.
Cheers,
Andrew Bromage