This is an absolute beginner Haskell question. Probably needs a couple of edits.
Given the following code:
import Data.Maybe
someFunction :: String b => Int -> Maybe b
someFunction x = Nothing
I get the error:
Main.hs@2:18-2:26`String' is applied to too many type arguments
In the type signature for `someFunction':
someFunction :: String b => Int -> Maybe b
I'd like to understand exactly why I see this error.
The a Similar signature works for:
import Data.Maybe
somethingElse :: Num b => Int -> Maybe b
somethingElse x = Nothing
What's the difference between Num and String that causes this? (probably because String is not a type class?)
Can I create a shorthand for String in a similar fashion to Num? (probably yes?)
How can I find the correct type class to use if I'm in such a situation?
UPDATE:
To illustrate the reason I want to have a shorthand for the String type:
somethingElse :: String -> String -> String -> String
somethingElse x s t = t ++ s ++ x
This compiles, but I'd prefer to write:
somethingElse :: ??? a => a -> a -> a -> a
somethingElse x s t = t ++ s ++ x
-XOverloadedStrings
? That makes string literals have typeIsString s => s
. – pyonNum
is a parametricclass
(or typeclass) while String is atype
( or alias for the data type[Char]
) that takes no type parameters. – Nadir SampaoliString
is already a synonym for[Char]
and it's reasonably short. If you have so manyString
parameters that you feel the need to introduce a shorthand notation, you should probably do some refactoring instead. – raymonadFoldable
andTraversable
(as well as their monomorphized versions) that capture certain aspects of a container, at least when it comes to reading. – Luc Danton