[Haskell-cafe] Re: practicality of typeful programming
daniil.elovkov at googlemail.com
Sun Jul 8 17:02:16 EDT 2007
2007/6/28, Pasqualino 'Titto' Assini <tittoassini at gmail.com>:
> Hi Daniil,
> I had a look at the paper and associated code that Oleg refers to there is no
> special parsing taking place:
> From Vector/read-examples.hs:
> v3 = do
> let m1 = $(dAM [[1,2],[3,4]])
> s <- readFile "Vector/example-data.txt"
> listMatRow (read s) (\(m2::AVector Double a) ->
> print $ m2 *> trans m1
> It does not make any difference if the list that is used to populate the
> matrix is specified in the code or read from a file.
> In both cases, if the list lenght is incorrect, an error is generated at
> run-time (I think, I cannot run the actual code).
Let me explain how I see what's going on there.
It looks like, indeed, in both cases (matrix read from a file and
matrix given in the program) the error will be reported at run-time.
But that is because in both those cases Frederik converts an untyped
value to a typed one, via listVec*, listMat*. The untyped values being
lists and lists of lists.
Compare that to what we see, for example, in Oleg's (and other's)
paper Strongly typed hetergeneous collections, where the value is
constructed as typed in the first place.
In case of reading from a file, an error obviously can't be reported
So, the 'parsing' takes place in both of those cases. But, indeed,
there seems to be no specific parsing, in the sense of graceful
(UnTyped -> Maybe Typed). I failed to find the place, but I suspect
there should be the 'error' function called somewhere in a class
method which builds the typed thing.
I think, the typechecker sees the constraint of (*>) and supposes the
correct type for that lambda bound parameter. Having guessed that, it
calls the appropriate instance's method. The latter fails to build the
right thing and fails with an error. This is only a guess.
More information about the Haskell-Cafe