简体   繁体   中英

What's the different between type constructor in Haskell and java generic type?

I am reading something about monad with no experience in Haskell and confused with the concept of type constructor.

A monad is a triple ( M , unitM , bindM ) consisting of a type constructor M and a pair of polymorphic functions.

 unitM :: a -> M a bindM :: M a -> (a -> M b) -> M b 

In Java:

public class M<T> {
    static <T> M<T> unit(T a)
    static <T,R> M<R> bind(M<T> a, Function<T,M<R>> f)
}

I considered they are the same, type constructor is just something like generic type in Java, am I right? If not, what's the difference?

You don't sound confused to me. That looks like an unusually accurate translation into Java of Haskell's Monad class.

In Haskell, a "type" is a concrete type with no un-specified parameters, like Integer , M<String> , or M<T> for any fixed T . Something with one or more remaining parameters, like just M , is a "type constructor", because it is like a constructor for types: it must be given one type argument (a value for T ) in order to produce a concrete type.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM