[Haskell-cafe] Haskell-Cafe Digest, Vol 99, Issue 9

Ivan Lazar Miljenovic ivan.miljenovic at gmail.com
Fri Nov 4 06:53:08 CET 2011


On 4 November 2011 16:21, yrazes <yrazes at gmail.com> wrote:
> Hi
> This is a very simple basic case, but I have a little trouble with this... I
> hope somebody can help me

First of all, it would help if you said what your actual trouble is.

> main :: IO()
> main = return :: f

The "return :: f" bit here doesn't make any sense:

* :: is used in type signatures, not as an operator in code; you
shouldn't need it (assuming your definition of f below is meant to be
there).

> tipos :: Int -> Int -> Int -> Float
> tipos a b c
> f = b / a * c
> where
>     (a,b,c) = (8,3,15)

Your definition of tipos isn't complete... what you've actually
defined is a new top-level value `f' (which is of type Fractional a =>
a).  You need to actually have "tipos a b c" _equal_ something.

Now, if you want to calculate "b/a*c" for inputs a, b and c, try
something like this:

import System.Environment(getArgs)

main :: IO ()
main = do [a,b,c] <- getArgs
                  print $ tipos (read a) (read b) (read c)

tipos :: Int -> Int -> Int -> Double
tipos a b c = fromIntegral b / fromIntegral b * fromIntegral c

-- 
Ivan Lazar Miljenovic
Ivan.Miljenovic at gmail.com
IvanMiljenovic.wordpress.com



More information about the Haskell-Cafe mailing list