Using Haskell Symbols

In the source code for the applicative instance, perhaps we have:

instance Applicative Maybe where
pure = Just

Just f  <*> m       = fmap f m
Nothing <*> _m      = Nothing

Just _m1 *> m2      = m2
Nothing  *> _m2     = Nothing

I thought that '_' is used as a template in templates. What is the meaning of the meanings "_m" and "_m2"? Is this a GHC coding convention? Is there a performance advantage for using _?

+4
source share
2 answers

, _ . , _; . _ , _ , . , GHC , , . , , , , ? , _ - Haskell, . GHC , _ -initial, , , .

,

Just f  <*> m  = fmap f m
Nothing <*> _m = Nothing

_m , , , m , . _, . m, :

…: warning: [-Wunused-matches]
    Defined but not used: ‘m’

, _ Haskell. " " ( , , ), _, . :

  • _.

    star1, star2 :: a -> b -> Char
    star1 _ _ = '*'
    star2 x y = '*'
    -- ILLEGAL:
    -- star3 x x = '*'
    

    _ - - . , , , , ; "x" . ( _ , .)

  • _ .

    id2 :: a -> a
    -- ILLEGAL:
    -- id1 _ = _
    id2 x = x
    

    _ "", , , . - .

+3

_, :

gcc -Wall test.hs:

test.hs:21:18: Warning: Defined but not used: ‘m

test.hs:23:11: Warning: Defined but not used: ‘m1

test.hs:24:18: Warning: Defined but not used: ‘m2

_, . , _var . - :

Justa m1 *> _m      = _m

- :

Just m1 *> _ = _
+1

Source: https://habr.com/ru/post/1676720/