0

What is the best way to rewrite the following so it compiles? Both data-type depends on each other.

{-# LANGUAGE OverloadedStrings, DuplicateRecordFields #-}   
data Syn = S { inputs :: [Neu] }
data Neu = N { weigth :: Double, inputs :: [ Syn ] }
Dilawar
  • 5,438
  • 9
  • 45
  • 58
  • 2
    This should compile. What is not working? In `ghci`, you will however need to write it as a multiline statement. – Willem Van Onsem Aug 08 '18 at 13:46
  • 3
    well the reason a single line will not work is because it first interprets the firs tline, and then `Neu` is unknown. But if you feed the two lines at the same time, then the compiler can *tie the knot* itself :). – Willem Van Onsem Aug 08 '18 at 13:51

1 Answers1

3

Your code compiles fine (I took the liberty of giving it a module name), there are not errors:

% ghc -c so.hs
% cat so.hs
{-# LANGUAGE OverloadedStrings, DuplicateRecordFields #-}
module So where

data Syn = S { inputs :: [Neu] }
data Neu = N { weigth :: Double, inputs :: [ Syn ] }

% ls -l so.o
-rw-r--r--  1 tommd  wheel  4888 Aug  8 14:02 so.o

If you are getting an error please be sure to post the actual code, the command used to compile or interpret, the version of the compiler, and the error message itself.

Thomas M. DuBuisson
  • 64,245
  • 7
  • 109
  • 166