Why is there no runConst function in Haskell? -
is there convention know when expect runx
versus getx
typeclass functions?
it's purely matter of how author preferred think they're representing. , it's more "abstract concept" being represented, not actual data structure being used represent it.
if have type x
, think of x
value computation run value, you'd have runx
function. if think of more container, you'd have getx
function (there other possible interpretations lead runx
or getx
or else, these 2 commonly recurring ways of thinking values).
of course when we're using first class haskell values represent things (and functions values), lot of time interpret either computation or container reasonably well. consider state
representing stateful computations; surely has interpreted computation, right? runstate :: state s -> s -> (a , s)
because think of "running" state s a
, needing s
additional input. think of "getting" s -> (a, s)
out of state s a
- treating state
more container.
so choice between runx
, getx
isn't meaningful in profound tense, tells how author thinking x
(and perhaps how think should think it).
const
so-named in analogy function const
(which takes argument produce "constant function" takes input, ignores it, , returns whatever first input const
was). it's thought of operating @ type level; const
takes type , generates "type-level function" ignores whatever type applied , isomorphic first type const
applied to. isomorphic rather equal because create new type have different instances, needs have constructor. @ value level, in order isomorphism need able const b
a
(that's const
constructor), , a
out of const b
. since "being isomorphic a
" all properties need have there's no real need think of doing other being simple container of a
, have getconst
.
identity
seems obvious "just container" , have runidentity
. 1 of main motivations having identity
think of identity a
being "monadic computation" in same way state s a
, reader e a
, etc values are. continue analogy think of identity
"do-nothing" computation run, rather simple wrapper container value out of. would valid think of identity
container (the simplest possible one), wasn't interpretation authors chose focus on.
Comments
Post a Comment