"Cannot find template" when using tag type with tags

I have an application that covers several modules. First, I model my problem by creating several data types. In the second, I put glances.

One of these types is the tagged join type:

type alias Letter = Char type GuessedLetter = Guessed Letter | Unguessed 

In my View module, I have a function to display a letter:

 guessToChar : GuessedLetter -> Char guessToChar guess = case guess of Guessed l -> l Unguessed -> '_' 

But when I try to compile these files, I get the following error:

 ## ERRORS in src/Views.elm ##################################################### -- NAMING ERROR -------------------------------------------------- src/Views.elm Cannot find pattern `Guessed` 21| Guessed l -> l ^^^^^^^^^ -- NAMING ERROR -------------------------------------------------- src/Views.elm Cannot find pattern `Unguessed` 22| Unguessed -> '_' ^^^^^^^^^ Detected errors in 1 module. 

I thought: “Maybe I need to export the tags, as well as the type?”, But neither adding tags to the module export nor trying to fully qualify the tags ( GuessedLetter.Guessed ) resolved the problem.

How to fix this feature?

+5
source share
1 answer

As I expected, if you want to use tags outside the module, you also need to export them . (I just don't know how).

To do this, add tags to the comma-separated list in parentheses.

From the source code for Maybe (the type that "worked" the way I wanted mine):

 module Maybe exposing ( Maybe(Just,Nothing) , andThen , map, map2, map3, map4, map5 , withDefault , oneOf ) 

Or in my case:

module Game exposing (Letter, GuessedLetter(Guessed, Unguessed))

On the import side, you can choose to fully qualify tags (with a module, not with a type):

 import Game exposing GuessedLetter {- ... -} guessToChar : GuessedLetter -> Char guessToChar guess = case guess of Game.Guessed l -> l Game.Unguessed -> '_' 

or set tags :

 import Game exposing GuessedLetter(Guessed, Unguessed) {- ... -} guessToChar : GuessedLetter -> Char guessToChar guess = case guess of Guessed l -> l Unguessed -> '_' 
+12
source

All Articles