[Haskell-beginners] Derived data

Michael Alan Dorman mdorman at ironicdesign.com
Tue Mar 24 10:21:22 UTC 2015


Mark Carter <alt.mcarter at gmail.com> writes:
> I read inputs from files into various data types. Not all of the
> information is known at input time, so some of the data for a type
> needs to be derived. The question is: what is the best way of
> "guarding" between derived and underived data?
>
> By that I mean, there is a function which will derive missing data,
> and other functions can only work on derived data. Working on
> underived data would be a mistake.

That seems like the straight-up definition of two data types:

    data Raw = Raw (Maybe Int) Text (Maybe Text)

    data Cooked = Cooked Text

    oven :: Raw -> Cooked

    -- Can't pass Raw data to consumer
    consumer :: Cooked -> Result

Mike.


More information about the Beginners mailing list