Create data constructor for partially applied type in Haskell -
is possible create data constructor partially applied type in haskell?
ghci session:
prelude> data vector b = vector {x::a, y::b} prelude> :t vector vector :: -> b -> vector b prelude> type t1 = vector int prelude> :t t1 <interactive>:1:1: not in scope: data constructor `t1' prelude> let x = vector prelude> let y = t1 <interactive>:46:9: not in scope: data constructor `t1'
i want create data constructor type t1 - possible? or have use newtypes, because not possible manually define such function?
i'm little confused goal is, let's go through bit bit, , maybe i'll hit right point:
:t
tells type of variable; makes no sense when applied type, since return passed. notice errors here tell :t
expects kind of data value parameter:
prelude> :t maybe <interactive>:1:1: not in scope: data constructor `maybe' prelude> :t (maybe integer) <interactive>:1:2: not in scope: data constructor `maybe' <interactive>:1:8: not in scope: data constructor `integer'
you can create partial type:
prelude> type t = maybe prelude> 5 :: t integer 5 type t = maybe -- alternately, explicit type parameters prelude> 'a' :: t char 'a'
you can't create data constructor partial type, since don't represent data. values maybe
or vector
have without being parameterized on type? might inclined think maybe
have value nothing
, nothing
typed as:
prelude> :t nothing nothing :: maybe
the key being nothing
can any maybe a
, still needs a
know it's nothing
. (it's sort of if told "fetch me glass of" instead of "fetch me glass of anything" - can't validly comply until i've @ least finished thought).
you can create partially applied functions return complete type once they're applied:
prelude> let f = :: -> t prelude> f 5 5 prelude> :t f 'a' f 'a' :: t char
Comments
Post a Comment