[Haskell-cafe] how can I do this the best

Richard A. O'Keefe ok at cs.otago.ac.nz
Tue Feb 24 01:07:56 UTC 2015

On 24/02/2015, at 5:19 am, Roelof Wobben <r.wobben at home.nl> wrote:

> I tried it another way more like explained on this page :  http://www.seas.upenn.edu/~cis194/spring13/lectures/02-ADTs.html
> so I tried this : 
> parseMessage :: [Char] -> [Char]
> parseMessage s
> case Errornumber of 
>     IsDigit Errornumber  -> "Geldige string"
>     otherwise            -> "Ongeldige string"
>   where
>       Error = s words
>       Errornumber = Error(ErrorNumber _ _ )
>       Errorcode = Error(_ Errorcode _ )
> but now I cannot use where :( 

That's not your problem.

IsDigit ErrorNumber is not a pattern.

parseMessage s =
    if isDigit errorNumber then "Geldige string"
    else                        "Ongelidige string"
    errorNumber = ???

is OK.  

Now I cannot make sense of
    Error = s words

	identifiers beginning with capital letters are used for
	- module names
	- type constructors
	- data constructors
	You want a variable here, so it must begin with a
	lower case letter.

	s words treats a string s as a function and applies it
	to the function words as argument: s(words).  But that
	does not type check.  You mean words s.

	The result of words s, whatever else it may be, is not
	an error.

    Errornumber = Error(ErrorNumber _ _)

	In the form "expr where pattern = expr", the thing after
	the equal sign must be an expression.  But
	Error(ErrorNumber _ _) is not an expression.  "_" is a
	PATTERN (= I do not care what goes here) but never an
	EXPRESSION (because what value would it have?).

More information about the Haskell-Cafe mailing list