The definitions of elemDecoder, elemDecoderType, and elemDecoderTypeHelp form a cycle, and the compiler has emitted the first two value definitions in an unlucky order (see the JS output below; the definition of elemDecoder references elemDecoderType before it’s defined). This is a known issue.
So when you inline the definition of elemDecoderType, you avoid the unlucky ordering. And in this case using lazy isn’t the only solution because the cycle includes a function, elemDecoderTypeHelp (which can be safely referenced before its definition). If the cycle were formed of only values, then you’d want to use lazy as @ilias described.
var _user$project$Main$elemDecoder = _elm_lang$core$Json_Decode$oneOf(
{
ctor: '::',
_0: _user$project$Main$elemDecoderChunk,
_1: {
ctor: '::',
_0: _user$project$Main$elemDecoderType,
_1: {ctor: '[]'}
}
});
var _user$project$Main$elemDecoderType = A2(
_elm_lang$core$Json_Decode$andThen,
_user$project$Main$elemDecoderTypeHelp,
A2(_elm_lang$core$Json_Decode$field, 'type', _elm_lang$core$Json_Decode$string));