|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today! |
|
#1
|
|||
|
|||
|
Haskell spaces
After running a test on this code I get;
Expected: Centre (5.5, 5.5), area 15.0 Actual: Centre (5.5,5.5), area 15.0 Which leaves me unaware of how to create a space between the coordinates. Any advice? Code:
-- Display the combined area and centre of a list of shapes. module Compound (combine) where import Shape -- Take a list of lines, convert into a list of shapes, -- and then find and report the combined centre and area. combine :: [String] -> String combine input = "Centre " ++ show(finalCentroid(input)) ++ ", area " ++ show (totalArea(input)) -- Work out the total area of all shapes totalArea :: [String] -> Double totalArea[] = 0 totalArea (x:xs) = area (shape x) + totalArea xs -- Work out the total of all x co-ordinates centroidX :: [String] -> Double centroidX [] = 0 centroidX (x:xs) = fst(centre (shape x)) + (centroidX xs) -- Work out the total for all y co-ordinates centroidY :: [String] -> Double centroidY[] = 0 centroidY (x:xs) = snd(centre (shape x)) + centroidY xs finalCentroid :: [String] -> Point finalCentroid (x:xs) = ((centroidX (x:xs))/(totalArea (x:xs)), (centroidY (x:xs))/(totalArea (x:xs))) |
|
#2
|
|||
|
|||
|
Quote:
read any basic haskell tutorial. If you still have a problem with this, you're on the wrong course. If not, do your homework. If you still have questions post on a sensible place to ask questions about haskell, like comp.lang.haskell. |
|
#3
|
|||
|
|||
|
__________________
Did this post help? Please Click The Next To My PostNeed help? Did you try Google? Take a look over at my current work in progress http://crispycrisp.org |
|
#4
|
|||
|
|||
|
Instance of mond
Hi all,
I hope here is the correct place where i can find the answer that i'm looking for. I'm writing a code for the xxtea, it is a modification for the Tiny encryption algorithm. The problem is that when i am running my code it is giving me this: "Instance of Monad (Array Word32) required for definition of coding" the code is below; hope some one will reply and tell what is the problem.thnx type TEA_arr = Array Word32 Word32 coding :: TEA_arr -> Word32 -> Word32 -> [Word32] -> Word32 -> Word32 -> TEA_arr coding v s e k 0 _ = v coding v s e k q p = do let sum = getSum s e = shiftSum sum y = v ! (p+1) z = v ! p mx = getMx y z sum k e p newarr = v // [(p,(v ! p)+ mx)] coding newarr sum e k (q - 1) (p+1) |
|
#5
|
|||
|
|||
|
Quote:
Did you read the previous message? Take a look around you and see if other people are asking and solving questions like yours. Are they? No. You could try haskell-cafe, but you might be unlikely to get much help until you read some basic tutorials and put in a bit of effort yourself. Hint: do blocks are only used with monadic code, which yours is not. Oh, and why hijack this thread then post your message again? With netiquette like that you might have to learn how to do your own homework. Bummer, eh? Last edited by jamieB : May 16th, 2007 at 11:28 AM. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Other Programming Languages > Haskell spaces |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|