I would like to create a structure datatype called Structured that can be used to represent String, Int and List. For example, structure is like: [Int, String, Int,[Int]].
Question 1: how to create this datatype?
data Structured = ...
Question 2: A function called Confirm that confirms the input satisfies a restriction, and has the signature type of confirm:: Restriction -> Structure ->Maybe Bool
would work.
seems a more sensible type, but has a trivial implementation as
id.I don’t think you would need to return
Maybe Boolfrom a valudation function –Maybe ais good for when you usually resturn ana, but sometimes don’t. (It’s good for very simple error handling, for example – giveNothingif there was an error.) In this case, you can always make a conclusion as to whether your input was valid, so you can always give backTrueorFalse– no need for theMaybe.Perhaps you could have something like
Here
int1:int2:intsis the list that hasint1in front ofint2in front ofints.A slightly nicer way of defining Structured would be:
then you’d have
It does the same job as the first data declaration, but gives you functions for getting at the internals.