Functions like Haskell?

Consider this ADT:

data Property f a = Property String (f a) | Zilch
  deriving Show

What is here f? Is this a function acting on a? Is this a type function? The instructor said that Haskell has a full type of Turing language ... so in this case, types can also have functions?

*Main> var = Property "Colors" [1,2,3,4]
*Main> :t var
var :: Num a => Property [] a

How fdoes it behave like []here? Since it []is a constructor for an empty list, fwill it always be the most external empty constructor for a type a, as in the following examples?

*Main> var = Property "Colors" [(1,"Red"),(2,"Blue")]
*Main> :t var
var :: Num t => Property [] (t, [Char])

*Main> var = Property "Colors" (1,"Red")
*Main> :t var
var :: Num t => Property ((,) t) [Char]

The last thing I did not quite understand, but if someone said that Haskell concluded that there was an empty constructor for this tuple, I normally buy it. On the other hand,

*Main> var = Property "Colors" 20
*Main> :t var
var :: Num (f a) => Property f a

what is here f? It cannot be an identity, because id :: a -> a, but we need (f a).

ADT

instance Functor f => Functor (Property f) where
  fmap fun (Property name a) = Property name (fmap fun a)
  fmap g Zilch               = Zilch 

, -

*Main> var = Property "Colors" [1,2,3,4]
*Main> fmap (+1) var
Property "Colors" [2,3,4,5]

, ?

( Haskell ), , FlexibleContexts, ... fmap a.

+6
4

() , [] Haskell, .

[] . Property "Colors" [1,2,3,4] Property [] a, , . . 1 [] - . [Int] ( ints), [Bool] ( bools) [a] ( a); [] - , Int, Bool a .

[Int] [] Int, , , [] , .

:

data Property f a = Property String (f a) | Zilch

Property; Property f a . , , (Property Zilch) "" ( Zilch, String f a, Property).

, , f a, f a (f, a) , . f ( ) ! Property f.

:

*Main> var = Property "Stuff" (Just True)
*Main> :t var
var :: Property Maybe Bool

, Maybe - , :

data Maybe a = Just a | Nothing

, , , , .

Just True - Maybe Bool. Just, True. Maybe, Bool. Maybe Bool f a Property, : f is Maybe a is Bool.

, :

*Main> var = Property "Colors" [1,2,3,4]
*Main> :t var
var :: Num a => Property [] a

f a [1, 2, 3, 4]. - , Num t => [t]. , a f a t ( Num, ), f - []. [] Maybe, Nothing.

*Main> var = Property "Colors" (1,"Red")
*Main> :t var
var :: Num t => Property ((,) t) [Char]

f a (1, "Red"), Num t => (t, [Char]) (, String - [Char]). , , . (t, [Char]). - - , f a. , , (, (a, b)), ADT, . 2- - , (,) , t [Char]. , (,) t , [Char]. Haskell ((,) t) [Char], , . , f a, "" (,) t f [Char] a. Property ((,) t) [Char] ( Num t, ).

, , :

*Main> var = Property "Colors" 20
*Main> :t var
var :: Num (f a) => Property f a

f a 20, . , , Haskell , Num. , "", f a: . f a, 20, Num. , f a, 20 , Num, Num (f a) => f a, , var - f a ( ).

, , Integer, Int, Double .., , f a ; - , -, -. Num, Haskell , ( ) , , , Num . , , , , Haskell ( ) Num , .

, Num. Ratio . Ratio Int Ratio Integer, :

Main*> 4 :: Ratio Int
4 % 1

, :

*Main> var = Property "Colors" (20 :: Ratio Integer)
*Main> :t var
var :: Property Ratio Integer

1 , DataKinds , , . , , , , , vanilla Haskell, , .

+5

f? , a? " "?

, , , , .. Type -> Type - , Haskell

> :k []
[] :: * -> *

f [] ? [] ...

. Haskell , []:

  1. [] :: [a]. ( -), , ).

  • [] :: * -> *. , . , , , .

Property [] a , , , , , f.

Property ((,) t) [Char]

: . ( ). (,) t , , , f.

+6

, Haskell Turing...

, . Haskell Turing. GHC , , Haskell Turing.

f [] ? [] , f a, ?

. Haskell :

data [] a = [] | a : ([] a)

[], - . [] , . , map map :: (a -> b) -> [] a -> [] b.

, data [], . [] , "" . "-" [] * -> *: .

Property, - * -> * -> *, . Property [] - * -> *.

+4

functors :

f ( ), , f ( kind haskell), * -> *, , .

var = Property "Colors" [1,2,3,4], var "" , [] , [] :k * -> *

:

var2 = Property "Perhaps A Bool" (Just True)

var2 :t:

var2 :: Property Maybe Bool

Why is this because Maybe also has a kind →, it waits for the type to return another, see type, it does not say (Maybe Bool) Bool it says Maybe Bool . Like your other example, for example, []instead[Int]

More on functors and types

0
source

All Articles