You could actually translate your Python code, mapping the syntactic structure almost literally to Haskell. What changes is
- You don't need
return (because in Haskell you always directly specify what the function returns, and only need extra syntax for managing monadic side effects – which this function doesn't have).
- On the flip side, you do need to have an
else in every if statement, because unlike in Python you can't just not return anything (well, arguably you can't do that in Python either, it just defaults to returning None if you don't explicitly return something else).
- You can't directly use
< on two different typed variables. Unlike Python, Haskell never does automatic type conversion, however you can explicitly do it with fromIntegral.
So,
f a d s =
if(s == "Is Integer less than Double")
then if(fromInteger a < d)
then "Yes, it is."
else "No, it isn't"
else {- ...whatever should happen in this case -}
Haskellers tend to not use if constructs though, but instead use guards for conditionals, i.e.
f a d s
| s == "Is Integer less than Double"
= if(fromInteger a < d)
then "Yes, it is."
else "No, it isn't"
| otherwise = {- ...whatever should happen in this case -}
That actually allows you to also omit the explicit fallback case, though the compiler will then warn about an incomplete match.
Anyway it's still not idiomatic: Haskellers avoid binding a function argument just to check it for equality. Instead, you just pattern match on the value you compare against:
f a d "Is Integer less than Double"
= if(fromInteger a < d)
then "Yes, it is."
else "No, it isn't"
f a d s = {- ...whatever should happen in this case -}
Now you can actually use guards for what was originally the inner if:
f a d "Is Integer less than Double"
| fromInteger a < d
= "Yes, it is."
| otherwise = "No, it isn't"
f a d s = {- ...whatever should happen in this case -}
If you really don't want to handle the case of any other string, then you should make that a failure case that's expressed also through the type signature:
f :: Integer -> Double -> String -> Maybe String
f a d "Is Integer less than Double"
| fromInteger a < d
= Just "Yes, it is."
| otherwise = Just "No, it isn't"
f _ _ _ = Nothing
fbe here?” – well,f a d s = ""would certainly be a possible definition, albeit a rather useless one. What do you want the function to do? If you can write how you'd do it in another language, perhaps Java and Python, we can answer how to translate that to Haskell.