{"action":"opened","issue":{"url":"https://api.github.com/repos/clash-lang/clash-compiler/issues/151","repository_url":"https://api.github.com/repos/clash-lang/clash-compiler","labels_url":"https://api.github.com/repos/clash-lang/clash-compiler/issues/151/labels{/name}","comments_url":"https://api.github.com/repos/clash-lang/clash-compiler/issues/151/comments","events_url":"https://api.github.com/repos/clash-lang/clash-compiler/issues/151/events","html_url":"https://github.com/clash-lang/clash-compiler/issues/151","id":158617392,"number":151,"title":"`imap` is not unrolled","user":{"login":"christiaanb","id":93169,"avatar_url":"https://avatars.githubusercontent.com/u/93169?v=3","gravatar_id":"","url":"https://api.github.com/users/christiaanb","html_url":"https://github.com/christiaanb","followers_url":"https://api.github.com/users/christiaanb/followers","following_url":"https://api.github.com/users/christiaanb/following{/other_user}","gists_url":"https://api.github.com/users/christiaanb/gists{/gist_id}","starred_url":"https://api.github.com/users/christiaanb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/christiaanb/subscriptions","organizations_url":"https://api.github.com/users/christiaanb/orgs","repos_url":"https://api.github.com/users/christiaanb/repos","events_url":"https://api.github.com/users/christiaanb/events{/privacy}","received_events_url":"https://api.github.com/users/christiaanb/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-06-06T07:38:58Z","updated_at":"2016-06-06T07:38:58Z","closed_at":null,"body":"The following code:\r\n\r\n```haskell\r\n{-# LANGUAGE ScopedTypeVariables #-} \r\n\r\nmodule Test2 where\r\nimport CLaSH.Prelude\r\nimport qualified Prelude as P\r\n\r\n-- apply input signal on function matching address\r\n-- other functions gets input nothing\r\n-- Does sythesize\r\nbusSwitch2 :: forall n a b . KnownNat n  \r\n          => Vec n (Signal (Maybe a) -> Signal b ) -- vector of functions\r\n          -> Signal (Index n)                      -- address as index of vectors\r\n          -> Signal (Maybe a)                      -- input\r\n          -> Vec n (Signal b)                      -- output\r\nbusSwitch2 vec addr inp = zipWith ($) vec r where\r\n    r = unbundle (liftA2 f addr inp)\r\n    f i a = replace i a (repeat Nothing)\r\n\r\n\r\n-- returns output from function where \r\n-- address applies\r\n-- other functions gets input nothing\r\n-- Does not sythesize\r\nbusSwitch1 :: forall n a b . KnownNat n  \r\n          => Vec n (Signal (Maybe a) -> Signal b ) -- vector of functions\r\n          -> Signal (Index n)                      -- address as index of vectors\r\n          -> Signal (Maybe a)                      -- input\r\n          -> Vec n (Signal b)                      -- output\r\nbusSwitch1 vec addr inp = r where\r\n    r = imap f vec\r\n    f :: Index n \r\n      -> (Signal (Maybe a) -> Signal b) \r\n      -> Signal b\r\n    f n x = x s where\r\n       s :: Signal (Maybe a)  \r\n       s = liftA2 fa inp addr\r\n       fa :: Maybe a \r\n          -> Index n \r\n          -> Maybe a\r\n       fa i a | n == a    = i \r\n              | otherwise = Nothing\r\n\r\n\r\n\r\n-- based on address modify input signal \r\ntopEntity :: Signal (Index 4)\r\n          -> Signal (Maybe (Signed 5))\r\n          -> Signal (Vec 4 (Maybe (Signed 5)))\r\ntopEntity i s = bundle $ busSwitch1 v i s where\r\n    v = f (+1)         -- if address == 0 increment 1\r\n     :> f (*2)         -- if address == 1 multiply 2\r\n     :> f (subtract 1) -- if address == 2 subtract \r\n     :> f negate       -- if address == 3 negate\r\n     :> Nil\r\n    f x = fmap (fmap x) \r\n```\r\n\r\nfails with:\r\n\r\n```\r\n*** Exception: CLaSH.Netlist(333): Unknown function: x15\r\n```\r\n\r\nThis is most likely due to `imap` not being unrolled at compile-time."}}
{"actor":{"display_login":"christiaanb"}}